url
stringlengths 36
137
| content
stringlengths 1.21k
7.75M
|
---|---|
https://www.mongodb.com/docs/manual/tutorial/create-chunks-in-sharded-cluster/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Create Ranges in a Sharded Cluster
<a class="headerlink leafygreen-ui-1kepx47" href="#create-ranges-in-a-sharded-cluster" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-ranges-in-a-sharded-cluster">
</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="#learn-more" target="_self">
<span>
Learn More
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
In most situations a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
will create, split, and
distribute ranges automatically without user intervention. However, in
some cases, MongoDB cannot create enough ranges or distribute data fast
enough to support the required throughput.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, if you want to ingest a large volume of data into a cluster
where you have inserts distributed across shards, pre-splitting the
ranges of an empty sharded collection can improve throughput.
</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 6.0, the balancer does not distribute empty
ranges. To pre-split the collection, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
to
distribute the empty ranges across the shards in the cluster.
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
automatically splits the range to be moved, meaning
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
performs both splitting and moving. You don't need to
manually split the range with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/split/#mongodb-dbcommand-dbcmd.split">
<code class="leafygreen-ui-1l06pbn">
split
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Alternatively, by defining the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/">
zones
and zone ranges
</a>
<em>
before
</em>
sharding an empty or a
non-existing collection, the shard collection operation creates ranges
for the defined zone ranges as well as any additional ranges to cover
the entire range of the shard key values and performs an initial range
distribution based on the zone ranges. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-initial-ranges-empty-collection">
Empty Collection
<!-- -->
.
</a>
</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">
Only pre-split ranges for an empty collection. Manually splitting
ranges for a populated collection can lead to unpredictable range
ranges and sizes as well as inefficient or ineffective balancing
behavior.
</p>
</div>
</div>
<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/bulk-write-operations/#std-label-bulk-write-sharded-collection">
Strategies for Bulk Inserts to a Sharded Collection
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
<code class="leafygreen-ui-1l06pbn">
sh.balancerCollectionStatus()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Initial ranges created and distributed by the sharding command,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-initial-ranges-empty-collection">
Empty Collection
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Balancer and automatic distribution of ranges across shards,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing-internals">
Balancer Internals
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-range-migration">
Range Migration
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Manually migrate ranges, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/migrate-chunks-in-sharded-cluster/#std-label-migrate-chunks-sharded-cluster">
Migrate Ranges in a Sharded Cluster
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$bitsAnySet
<a class="headerlink leafygreen-ui-1kepx47" href="#-bitsanyset" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-bitsanyset">
</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="#examples" target="_self">
<span>
Examples
</span>
</a>
</li>
</ul>
</div>
<dl class="query">
<dt>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-bitsAnySet" 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.-bitsAnySet">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
matches documents where
<em>
any
</em>
of the bit positions
given by the query are set (i.e.
<code class="leafygreen-ui-1l06pbn">
1
</code>
) in
<code class="leafygreen-ui-1l06pbn">
field
</code>
.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<thead class="leafygreen-ui-a9ho40">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ <field>: { $bitsAnySet: <numeric bitmask> } }
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ <field>: { $bitsAnySet: <
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
<code class="leafygreen-ui-1l06pbn">
bitmask> } }
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ <field>: { $bitsAnySet: [ <position1>, <position2>, ... ] } }
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
field
</code>
value must be either numeric or a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
instance. Otherwise,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
will not match the current document.
</p>
<dl>
<dt>
Numeric Bitmask
</dt>
<dd class="css-1ufxuu7">
You can provide a numeric bitmask to be matched against the operand field.
The bitmask must be a non-negative 64-bit signed integer.
Otherwise,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
returns an error.
</dd>
<dt>
BinData Bitmask
</dt>
<dd class="css-1ufxuu7">
You can also use an arbitrarily large
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
instance as a bitmask.
</dd>
<dt>
Position List
</dt>
<dd class="css-1ufxuu7">
If querying a list of bit positions, each
<code class="leafygreen-ui-1l06pbn">
<position>
</code>
must be a non-negative
integer. Bit positions start at
<code class="leafygreen-ui-1l06pbn">
0
</code>
from the least significant bit. For
example, the decimal number
<code class="leafygreen-ui-1l06pbn">
254
</code>
would have the following bit positions:
</dd>
</dl>
<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>
Bit Value
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
1
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
0
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Position
</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
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
5
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
4
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
3
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2
</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>
0
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</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">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-endianness">
endianness
</a>
of your system depends on the architecture of
your machine. Numbers in BSON data are always stored as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-little-endian">
little-endian
</a>
, if your system is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-big-endian">
big-endian
</a>
this means
that numeric data is converted between big and little endian.
</p>
<p class="leafygreen-ui-1kp3ins">
In the context of the bit-test match expression operators:
</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="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/bitsAnyClear/#mongodb-query-op.-bitsAnyClear">
<code class="leafygreen-ui-1l06pbn">
$bitsAnyClear
</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/bitsAllSet/#mongodb-query-op.-bitsAllSet">
<code class="leafygreen-ui-1l06pbn">
$bitsAllSet
</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/bitsAllClear/#mongodb-query-op.-bitsAllClear">
<code class="leafygreen-ui-1l06pbn">
$bitsAllClear
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
values act as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Mask_(computing)" rel="noopener noreferrer">
<span>
bitmasks
</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>
and are
interpreted as though they are arbitrary-length unsigned little-endian
numbers. The lowest-addressable byte is always interpreted as the least
significant byte. Similarly, the highest-addressable byte in the
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
is always interpreted as the most significant byte.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<p class="leafygreen-ui-1kp3ins">
Queries cannot use indexes for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
portion of a
query, although the other portions of a query can use indexes, if
applicable.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Floating Point Values
<a class="headerlink leafygreen-ui-1kepx47" href="#floating-point-values" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="floating-point-values">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
will not match numerical values that cannot be represented as
a signed 64-bit integer. This can be the case if a value is either too large
or too small to fit in a signed 64-bit integer, or if it has a fractional
component.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sign Extension
<a class="headerlink leafygreen-ui-1kepx47" href="#sign-extension" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sign-extension">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Numbers are sign extended. For example,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
considers bit position
<code class="leafygreen-ui-1l06pbn">
200
</code>
to be set for the negative number
<code class="leafygreen-ui-1l06pbn">
-5
</code>
, but bit position
<code class="leafygreen-ui-1l06pbn">
200
</code>
to be clear
for the positive number
<code class="leafygreen-ui-1l06pbn">
+5
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
In contrast,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-Binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
instances are zero-extended.
For example, given the following document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.insertOne({ x: BinData(0, \"ww==\"), binaryValueofA: \"11000011\" })","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">insertOne</span>(<!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"ww=="</span>)<!-- -->, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"11000011"</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-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
will consider all bits outside of
<code class="leafygreen-ui-1l06pbn">
x
</code>
to be clear.
</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>
<p class="leafygreen-ui-1kp3ins">
The following examples will use a 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.collection.insertMany([\n { _id: 1, a: 54, binaryValueofA: \"00110110\" },\n { _id: 2, a: 20, binaryValueofA: \"00010100\" },\n { _id: 3, a: 20.0, binaryValueofA: \"00010100\" },\n { _id: 4, a: BinData(0, \"Zg==\"), binaryValueofA: \"01100110\" }\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">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">a</span>: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00110110"</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">a</span>: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00010100"</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">a</span>: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"00010100"</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">a</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-attr">binaryValueofA</span>: <span class="lg-highlight-string">"01100110"</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">
Bit Position Array
<a class="headerlink leafygreen-ui-1kepx47" href="#bit-position-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="bit-position-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following query uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
operator to test
whether field
<code class="leafygreen-ui-1l06pbn">
a
</code>
has either bit position
<code class="leafygreen-ui-1l06pbn">
1
</code>
or bit position
<code class="leafygreen-ui-1l06pbn">
5
</code>
set,
where the least significant bit is position
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnySet: [ 1, 5 ] } } )","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-attr">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnySet</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">5</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 query matches the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"a\" : 54, \"binaryValueofA\" : \"00110110\" }\n{ \"_id\" : 4, \"a\" : BinData(0,\"Zg==\"), \"binaryValueofA\" : \"01100110\" }","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">"a"</span> <!-- -->: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00110110"</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">"a"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"01100110"</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">
Integer Bitmask
<a class="headerlink leafygreen-ui-1kepx47" href="#integer-bitmask" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="integer-bitmask">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following query uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
operator to test
whether field
<code class="leafygreen-ui-1l06pbn">
a
</code>
has any bits set at positions
<code class="leafygreen-ui-1l06pbn">
0
</code>
,
<code class="leafygreen-ui-1l06pbn">
1
</code>
, and
<code class="leafygreen-ui-1l06pbn">
5
</code>
(the binary representation of the bitmask
<code class="leafygreen-ui-1l06pbn">
35
</code>
is
<code class="leafygreen-ui-1l06pbn">
00100011
</code>
).
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnySet: 35 } } )","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-attr">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnySet</span>: <span class="lg-highlight-number">35</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 query matches the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"a\" : 54, \"binaryValueofA\" : \"00110110\" }\n{ \"_id\" : 4, \"a\" : BinData(0,\"Zg==\"), \"binaryValueofA\" : \"01100110\" }","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">"a"</span> <!-- -->: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00110110"</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">"a"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"01100110"</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">
BinData Bitmask
<a class="headerlink leafygreen-ui-1kepx47" href="#bindata-bitmask" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="bindata-bitmask">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following query uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-bitsAnySet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$bitsAnySet
</code>
</span>
</a>
operator to test
whether field
<code class="leafygreen-ui-1l06pbn">
a
</code>
has any bits set at positions
<code class="leafygreen-ui-1l06pbn">
4
</code>
, and
<code class="leafygreen-ui-1l06pbn">
5
</code>
(the binary representation of
<code class="leafygreen-ui-1l06pbn">
BinData(0, "MA==")
</code>
is
<code class="leafygreen-ui-1l06pbn">
00110000
</code>
).
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { a: { $bitsAnySet: BinData(0, \"MA==\") } } )","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">a</span>: <!-- -->{ <span class="lg-highlight-attr">$bitsAnySet</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"MA=="</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 query matches the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"a\" : 54, \"binaryValueofA\" : \"00110110\" }\n{ \"_id\" : 2, \"a\" : 20, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 3, \"a\" : 20.0, \"binaryValueofA\" : \"00010100\" }\n{ \"_id\" : 4, \"a\" : BinData(0,\"Zg==\"), \"binaryValueofA\" : \"01100110\" }","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">"a"</span> <!-- -->: <span class="lg-highlight-number">54</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00110110"</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">"a"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</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">"a"</span> <!-- -->: <span class="lg-highlight-number">20.0</span>, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"00010100"</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">"a"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"Zg=="</span>)<!-- -->, <span class="lg-highlight-string">"binaryValueofA"</span> <!-- -->: <span class="lg-highlight-string">"01100110"</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/maxN-array-element/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$maxN (array operator)
<a class="headerlink leafygreen-ui-1kepx47" href="#-maxn--array-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="-maxn--array-operator-">
</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="#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">
$maxN
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-maxN" 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.-maxN">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.2
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns the
<code class="leafygreen-ui-1l06pbn">
n
</code>
largest values in an array.
</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/minN-array-element/#mongodb-expression-exp.-minN">
<code class="leafygreen-ui-1l06pbn">
$minN
</code>
</a>
</p>
</div>
</div>
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-maxN" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$maxN
</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":"{ $maxN: { n: <expression>, input: <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">$maxN</span>: <!-- -->{ <span class="lg-highlight-attr">n</span>: <<!-- -->expression<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">input</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>
<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">
n
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
An
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to a
positive integer. The integer specifies the number of array elements
that
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-maxN" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$maxN
</code>
</span>
</a>
returns.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
input
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
An
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to the
array from which to return the maximal
<code class="leafygreen-ui-1l06pbn">
n
</code>
elements.
</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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot specify a value of
<code class="leafygreen-ui-1l06pbn">
n
</code>
less than
<code class="leafygreen-ui-1l06pbn">
1
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-maxN" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$maxN
</code>
</span>
</a>
filters out
<code class="leafygreen-ui-1l06pbn">
null
</code>
values found in the
<code class="leafygreen-ui-1l06pbn">
input
</code>
array.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the specified
<code class="leafygreen-ui-1l06pbn">
n
</code>
is greater than or equal to the number of elements
in the
<code class="leafygreen-ui-1l06pbn">
input
</code>
array,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-maxN" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$maxN
</code>
</span>
</a>
returns all elements in the
<code class="leafygreen-ui-1l06pbn">
input
</code>
array.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
input
</code>
resolves to a non-array value, the aggregation
operation errors.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
input
</code>
contains both numeric and string elements, the string elements
are sorted before numeric elements according to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-bson-types-comparison-order">
BSON comparison order
<!-- -->
.
</a>
</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>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
scores
</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.scores.insertMany([\n { \"playerId\" : 1, \"score\" : [ 1, 2, 3 ] },\n { \"playerId\" : 2, \"score\" : [ 12, 90, 7, 89, 8 ] },\n { \"playerId\" : 3, \"score\" : [ null ] },\n { \"playerId\" : 4, \"score\" : [ ] }\n { \"playerId\" : 5, \"score\" : [ 1293, \"2\", 3489, 9 ]}\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">scores</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">"playerId"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">8</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-literal">null</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <!-- -->] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"playerId"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"score"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">1293</span>, <span class="lg-highlight-string">"2"</span>, <span class="lg-highlight-number">3489</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">
The following example uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-maxN" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$maxN
</code>
</span>
</a>
operator to retrieve the two
highest scores for each player. The highest scores are returned in the new field
<code class="leafygreen-ui-1l06pbn">
maxScores
</code>
created by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/addFields/#mongodb-pipeline-pipe.-addFields">
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.scores.aggregate([\n { $addFields: { maxScores: { $maxN: { n: 2, input: \"$score\" } } } }\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">scores</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">maxScores</span>: <!-- -->{ <span class="lg-highlight-attr">$maxN</span>: <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$score"</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":"[{\n \"playerId\": 1,\n \"score\": [ 1, 2, 3 ],\n \"maxScores\": [ 3, 2 ]\n},\n{\n \"playerId\": 2,\n \"score\": [ 12, 90, 7, 89, 8 ],\n \"maxScores\": [ 90, 89 ]\n},\n{\n \"playerId\": 3,\n \"score\": [ null ],\n \"maxScores\": [ ]\n},\n{\n \"playerId\": 4,\n \"score\": [ ],\n \"maxScores\": [ ]\n},\n{\n \"playerId\": 5,\n \"score\": [ 1293, \"2\", 3489, 9 ],\n \"maxScores\": [ \"2\", 3489 ]\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">"playerId"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>, <span class="lg-highlight-number">3</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxScores"</span>: <!-- -->[ <span class="lg-highlight-number">3</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-string">"playerId"</span>: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">7</span>, <span class="lg-highlight-number">89</span>, <span class="lg-highlight-number">8</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxScores"</span>: <!-- -->[ <span class="lg-highlight-number">90</span>, <span class="lg-highlight-number">89</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">"playerId"</span>: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-literal">null</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxScores"</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">"playerId"</span>: <span class="lg-highlight-number">4</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <!-- -->]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxScores"</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">"playerId"</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <!-- -->[ <span class="lg-highlight-number">1293</span>, <span class="lg-highlight-string">"2"</span>, <span class="lg-highlight-number">3489</span>, <span class="lg-highlight-number">9</span> ]<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxScores"</span>: <!-- -->[ <span class="lg-highlight-string">"2"</span>, <span class="lg-highlight-number">3489</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/connection-string-options/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Connection String Options
<a class="headerlink leafygreen-ui-1kepx47" href="#connection-string-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="connection-string-options">
</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="#replica-set-option" target="_self">
<span>
Replica Set Option
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#connection-options" target="_self">
<span>
Connection Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#tls-options" target="_self">
<span>
TLS Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#timeout-options" target="_self">
<span>
Timeout Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#compression-options" target="_self">
<span>
Compression Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#connection-pool-options" target="_self">
<span>
Connection Pool Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#write-concern-options" target="_self">
<span>
Write Concern Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#readconcern-options" target="_self">
<span>
readConcern Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-preference-options" target="_self">
<span>
Read Preference Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#authentication-options" target="_self">
<span>
Authentication Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#server-selection-and-discovery-options" target="_self">
<span>
Server Selection and Discovery Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#miscellaneous-configuration" target="_self">
<span>
Miscellaneous Configuration
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page lists all connection option for both SRV connection
strings and standard connection strings.
</p>
<p class="leafygreen-ui-1kp3ins">
Connection options are pairs in the following form:
<code class="leafygreen-ui-1l06pbn">
name=value
</code>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The option
<code class="leafygreen-ui-1l06pbn">
name
</code>
is case insensitive when using a driver.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The option
<code class="leafygreen-ui-1l06pbn">
name
</code>
is case insensitive 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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
value
</code>
is always case sensitive.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Separate options with the ampersand (
<code class="leafygreen-ui-1l06pbn">
&
</code>
) character
<code class="leafygreen-ui-1l06pbn">
name1=value1&name2=value2
</code>
. In the following example, a
connection includes the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.replicaSet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replicaSet
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.connectTimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
connectTimeoutMS
</code>
</span>
</a>
options:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected]:27017,db2.example.net:2500/?replicaSet=test&connectTimeoutMS=300000"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected]:27017,db2.example.net:2500/?replicaSet=test&connectTimeoutMS=300000</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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>
Semi-colon separator for connection string arguments
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To provide backwards compatibility, drivers currently accept
semi-colons (
<code class="leafygreen-ui-1l06pbn">
;
</code>
) as option separators.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-option">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Replica Set Option
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-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="replica-set-option">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following connection string connects to a replica set named
<code class="leafygreen-ui-1l06pbn">
myRepl
</code>
with members running on the specified hosts. It
authenticates as user
<code class="leafygreen-ui-1l06pbn">
myDatabaseUser
</code>
with the password
<code class="leafygreen-ui-1l06pbn">
D1fficultP%40ssw0rd
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected]:27017,db1.example.com:27017,db2.example.com:27017/?replicaSet=myRepl","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">mongodb:/<!-- -->/my<!-- -->DatabaseUser:D1fficultP%[email protected]:27017,db1.example.com:27017,db2.example.com:27017/?replicaSet=myRepl</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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: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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
replicaSet
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.replicaSet" 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-urioption-urioption.replicaSet">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the name of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
, if 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 a member of a replica set. Set the
<code class="leafygreen-ui-1l06pbn">
replicaSet
</code>
connection option to ensure consistent behavior across drivers.
</p>
<p class="leafygreen-ui-1kp3ins">
When connecting to a replica set, provide a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-seed-list">
seed list
</a>
of
the replica set member(s) to the
<code class="leafygreen-ui-1l06pbn">
host[:port]
</code>
component of the
uri. For specific details, refer to your
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver
</span>
</a>
documentation.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
directConnection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.directConnection" 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-urioption-urioption.directConnection">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies whether the client connects directly to the
<code class="leafygreen-ui-1l06pbn">
host[:port]
</code>
in the
connection URI:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
: The client sends operations to only the specified host. It doesn't
attempt to discover any other members of the replica set.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
: The client attempts to discover all servers in the replica set,
and sends operations to the primary member. This is the default value.
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Connection Options
<a class="headerlink leafygreen-ui-1kepx47" href="#connection-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="connection-options">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-uri-options-tls">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
TLS Options
<a class="headerlink leafygreen-ui-1kepx47" href="#tls-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="tls-options">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following connection string to a replica set includes
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.tls" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
tls=true
</code>
</span>
</a>
option. It authenticates as user
<code class="leafygreen-ui-1l06pbn">
myDatabaseUser
</code>
with the password
<code class="leafygreen-ui-1l06pbn">
D1fficultP%40ssw0rd
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&tls=true"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&tls=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">
Alternatively, you can also use the equivalent
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.ssl" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
ssl=true
</code>
</span>
</a>
option:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&ssl=true"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&ssl=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>
<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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tls
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tls" 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-urioption-urioption.tls">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Enables or disables TLS/SSL for the connection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
: Initiate the connection with TLS/SSL. Default for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-connections-dns-seedlist">
SRV Connection Format
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
: Initiate the connection without TLS/SSL. Default for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-connections-standard-connection-string-format">
Standard Connection String Format
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.tls" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
tls
</code>
</span>
</a>
option is equivalent to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.ssl" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
ssl
</code>
</span>
</a>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
If 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 specifies additional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shellmongosh-tls/" target="_self">
<span>
tls/ssl
</span>
</a>
options from the
command-line, use the
<code class="leafygreen-ui-1l06pbn">
--tls
</code>
command-line option instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
ssl
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.ssl" 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-urioption-urioption.ssl">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A boolean to enable or disable TLS/SSL for the connection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
: Initiate the connection with TLS/SSL. Default for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-connections-dns-seedlist">
SRV Connection Format
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
: Initiate the connection without TLS/SSL. Default
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string/#std-label-connections-standard-connection-string-format">
Standard Connection String Format
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.ssl" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
ssl
</code>
</span>
</a>
option is equivalent to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.tls" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
tls
</code>
</span>
</a>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
If 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 specifies additional
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shellmongosh-ssl/" target="_self">
<span>
tls/ssl
</span>
</a>
options from the
command-line, use the
<code class="leafygreen-ui-1l06pbn">
--ssl
</code>
command-line option instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsCertificateKeyFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsCertificateKeyFile" 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-urioption-urioption.tlsCertificateKeyFile">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the location of a local
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that
contains either the client's TLS/SSL X.509 certificate or the
client's TLS/SSL certificate and key.
</p>
<p class="leafygreen-ui-1kp3ins">
The client presents this file 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>
/
<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">
<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>
logs a warning on
connection if the presented x.509 certificate expires within
<code class="leafygreen-ui-1l06pbn">
30
</code>
days of the
<code class="leafygreen-ui-1l06pbn">
mongod/mongos
</code>
host system time.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsCertificateKeyFilePassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsCertificateKeyFilePassword" 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-urioption-urioption.tlsCertificateKeyFilePassword">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the password to de-crypt the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.tlsCertificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
tlsCertificateKeyFile
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsCAFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsCAFile" 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-urioption-urioption.tlsCAFile">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the location of a local
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that
contains the root certificate chain from the Certificate
Authority. This file is used to validate the certificate
presented 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">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsAllowInvalidCertificates
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsAllowInvalidCertificates" 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-urioption-urioption.tlsAllowInvalidCertificates">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Bypasses validation of the certificates presented 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">
Set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to connect to MongoDB instances even if the
server's present invalid certificates.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-4dei7l">
WARNING:
</strong>
Disabling certificate validation creates a vulnerability.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsAllowInvalidHostnames
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsAllowInvalidHostnames" 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-urioption-urioption.tlsAllowInvalidHostnames">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Disables hostname validation of the certificate presented 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">
Set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to connect to MongoDB instances even if the
hostname in the server certificates do not match the server's
host.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-4dei7l">
WARNING:
</strong>
Disabling certificate validation creates a vulnerability.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
tlsInsecure
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.tlsInsecure" 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-urioption-urioption.tlsInsecure">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Disables various certificate validations.
</p>
<p class="leafygreen-ui-1kp3ins">
Set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to disable certificate validations. The exact
validatations disabled vary by drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell.
Use the command-line option instead.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-4dei7l">
WARNING:
</strong>
Disabling certificate validation creates a vulnerability.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Timeout Options
<a class="headerlink leafygreen-ui-1kepx47" href="#timeout-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="timeout-options">
</div>
</a>
</h3>
<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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
connectTimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.connectTimeoutMS" 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-urioption-urioption.connectTimeoutMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The time in milliseconds to attempt a connection before timing
out. The default is 10,000 milliseconds, but specific drivers
might have a different default. 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.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
socketTimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.socketTimeoutMS" 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-urioption-urioption.socketTimeoutMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The time in milliseconds to attempt a send or receive on a
socket before the attempt times out. The default is never to
timeout, though different drivers might vary. See the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver
</span>
</a>
documentation.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compression Options
<a class="headerlink leafygreen-ui-1kepx47" href="#compression-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="compression-options">
</div>
</a>
</h3>
<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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
compressors
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.compressors" 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-urioption-urioption.compressors">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Comma-delimited string of compressors to enable
network compression for communication between this
client and a
<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 specify the following compressors:
</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-snappy">
snappy
</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-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">
If you specify multiple compressors, then the order in which you list
the compressors matter as well as the communication initiator. For
example, if the client specifies the following network
compressors
<code class="leafygreen-ui-1l06pbn">
"zlib,snappy"
</code>
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>
specifies
<code class="leafygreen-ui-1l06pbn">
"snappy,zlib"
</code>
, messages between the client 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>
uses
<code class="leafygreen-ui-1l06pbn">
zlib
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Messages are compressed when both parties enable network
compression. Otherwise, messages between the parties are
uncompressed.
</p>
<p class="leafygreen-ui-1kp3ins">
If the parties do not share at least one common compressor,
messages between the parties are uncompressed.
</p>
<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>
supports the uri connection string
option
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.compressors" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
compressors
</code>
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
zlibCompressionLevel
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.zlibCompressionLevel" 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-urioption-urioption.zlibCompressionLevel">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
An integer that specifies the compression level if using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zlib">
zlib
</a>
for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.compressors" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
network compression
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify an integer value ranging from
<code class="leafygreen-ui-1l06pbn">
-1
</code>
to
<code class="leafygreen-ui-1l06pbn">
9
</code>
:
</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>
Value
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Notes
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
-1
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Default compression level, usually level
<code class="leafygreen-ui-1l06pbn">
6
</code>
compression.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
0
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
No compression
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
1
</code>
-
<code class="leafygreen-ui-1l06pbn">
9
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Increasing level of compression but at the cost of speed, with:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
providing the best speed but least compression, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
9
</code>
providing the best compression but at the slowest speed.
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Supported by
<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>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-connection-pool-options">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Connection Pool Options
<a class="headerlink leafygreen-ui-1kepx47" href="#connection-pool-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="connection-pool-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Most drivers implement some kind of connection pool handling.
Some drivers do not support connection
pools. See your
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
driver
</span>
</a>
documentation
for more information on the connection pooling implementation. These
options allow applications to configure the connection pool when
connecting to the MongoDB deployment.
</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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
maxPoolSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.maxPoolSize" 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-urioption-urioption.maxPoolSize">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The maximum number of connections in the connection pool. The
default value is
<code class="leafygreen-ui-1l06pbn">
100
</code>
.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
minPoolSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.minPoolSize" 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-urioption-urioption.minPoolSize">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The minimum number of connections in the connection pool. The
default value is
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.minPoolSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
minPoolSize
</code>
</span>
</a>
option is not supported by all
drivers. For information on your driver, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
maxConnecting
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.maxConnecting" 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-urioption-urioption.maxConnecting">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Maximum number of connections a pool may be establishing
concurrently. The default value is
<code class="leafygreen-ui-1l06pbn">
2
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
maxConnecting
</code>
is supported for all drivers
<strong>
except
</strong>
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/rust/current/" target="_self">
<span>
Rust Driver
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Raising the value of
<code class="leafygreen-ui-1l06pbn">
maxConnecting
</code>
allows the client to establish
connection to the server faster, but increases the chance of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-connection-storm">
connection storms
</a>
. If the value of
<code class="leafygreen-ui-1l06pbn">
maxConnecting
</code>
is too low, your connection pool may experience heavy
throttling and increased tail latency for clients checking out
connections.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
maxIdleTimeMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.maxIdleTimeMS" 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-urioption-urioption.maxIdleTimeMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The maximum number of milliseconds that a connection can remain
idle in the pool before being removed and closed.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
waitQueueMultiple
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.waitQueueMultiple" 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-urioption-urioption.waitQueueMultiple">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A number that the driver multiplies the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.maxPoolSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxPoolSize
</code>
</span>
</a>
value to, to provide the maximum number of threads allowed to
wait for a connection to become available from the pool. For
default values, 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>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
waitQueueTimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.waitQueueTimeoutMS" 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-urioption-urioption.waitQueueTimeoutMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The maximum time in milliseconds that a thread can wait for a
connection to become available. For default values, 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>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-connections-write-concern">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Write Concern Options
<a class="headerlink leafygreen-ui-1kepx47" href="#write-concern-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="write-concern-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write concern
</a>
describes the level of
acknowledgment requested from MongoDB. The write concern option is
supported by the:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB drivers
</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/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</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/database-tools/mongofiles/#mongodb-binary-bin.mongofiles" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongofiles
</code>
</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/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoimport
</code>
</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/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongorestore
</code>
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You can specify the write concern both in the connection string and
as a parameter to methods like
<code class="leafygreen-ui-1l06pbn">
insert
</code>
or
<code class="leafygreen-ui-1l06pbn">
update
</code>
. If the
write concern is specified in both places, the method parameter
overrides the connection-string setting.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB Atlas deployment connection strings use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
by default. If you don't specify write concern for an MongoDB Atlas
deployment, MongoDB Atlas enforces
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The following connection string to a replica set specifies
<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 and a 5 second
timeout using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.wtimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
wtimeoutMS
</code>
</span>
</a>
write concern parameter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&w=majority&wtimeoutMS=5000"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&w=majority&wtimeoutMS=5000</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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: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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
w
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.w" 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-urioption-urioption.w">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Corresponds to the write concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
<code class="leafygreen-ui-1l06pbn">
w
</code>
Option
</a>
. The
<code class="leafygreen-ui-1l06pbn">
w
</code>
option
requests acknowledgment that the write operation has propagated
to a specified 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>
instances or 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 with specified tags.
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-number-">
<code class="leafygreen-ui-1l06pbn">
number
</code>
</a>
, the
string
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
majority
</code>
</a>
, or a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-custom-write-concern-name-">
<code class="leafygreen-ui-1l06pbn">
tag set
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
<code class="leafygreen-ui-1l06pbn">
w
</code>
Option
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
wtimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.wtimeoutMS" 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-urioption-urioption.wtimeoutMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Corresponds to the write concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-wtimeout">
<code class="leafygreen-ui-1l06pbn">
wtimeout
</code>
</a>
.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.wtimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
wtimeoutMS
</code>
</span>
</a>
specifies a time limit, in milliseconds,
for the write concern.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
wtimeoutMS
</code>
is
<code class="leafygreen-ui-1l06pbn">
0
</code>
, write operations will never time
out. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-wtimeout">
<code class="leafygreen-ui-1l06pbn">
wtimeout
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
journal
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.journal" 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-urioption-urioption.journal">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Corresponds to the write concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-j">
<code class="leafygreen-ui-1l06pbn">
j
</code>
Option
</a>
option. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.journal" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
journal
</code>
</span>
</a>
option requests acknowledgment from
MongoDB that the write operation has been written to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-internals">
journal
</a>
. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-j">
<code class="leafygreen-ui-1l06pbn">
j
</code>
Option
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.journal" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
journal
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, and specify a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.w" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
w
</code>
</span>
</a>
value less than 1,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.journal" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
journal
</code>
</span>
</a>
prevails.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write Concern
<!-- -->
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
readConcern Options
<a class="headerlink leafygreen-ui-1kepx47" href="#readconcern-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="readconcern-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For the WiredTiger storage engine, MongoDB introduces the
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
option for replica sets and replica set shards.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/">
Read Concern
</a>
allows clients to choose a level of
isolation for their reads from replica sets.
</p>
<p class="leafygreen-ui-1kp3ins">
The following connection string to a replica set specifies
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.readConcernLevel" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
readConcernLevel=majority
</code>
:
</span>
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&readConcernLevel=majority"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&readConcernLevel=majority</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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: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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
readConcernLevel
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.readConcernLevel" 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-urioption-urioption.readConcernLevel">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The level of isolation. Can accept one of the following values:
</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-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<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-available/#mongodb-readconcern-readconcern.-available-">
<code class="leafygreen-ui-1l06pbn">
available
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available 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>
. Specify the read concern as an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern-operations">
option to the specific operation
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/">
Read Concern
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-connections-read-preference">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read Preference Options
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference-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="read-preference-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
Read preferences
</a>
describe the
behavior of read operations with regards to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica sets
</a>
. These parameters allow you to specify read preferences
on a per-connection basis in the connection string.
</p>
<p class="leafygreen-ui-1kp3ins">
For example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The following connection string to a replica set specifies
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
read preference mode and a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.maxStalenessSeconds" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
</span>
</a>
value of 120 seconds:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&readPreference=secondary&maxStalenessSeconds=120"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],db1.example.com,db2.example.com/?replicaSet=myRepl&readPreference=secondary&maxStalenessSeconds=120</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
The following connection string to a sharded cluster specifies
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
read preference mode and a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.maxStalenessSeconds" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
</span>
</a>
value of 120 seconds:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],mongos2.example.com/?readPreference=secondary&maxStalenessSeconds=120"}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],mongos2.example.com/?readPreference=secondary&maxStalenessSeconds=120</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
The following connection string to a sharded cluster specifies
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
read preference mode as well as three
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.readPreferenceTags" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
:
</span>
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongodb://myDatabaseUser:D1fficultP%[email protected],mongos2.example.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=dc:ny&readPreferenceTags="}
</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">mongodb://myDatabaseUser:D1fficultP%[email protected],mongos2.example.com/?readPreference=secondary&readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=dc:ny&readPreferenceTags=</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Order matters when using multiple
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
. The
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
are tried in order until a match is found. Once
found, that specification is used to find all eligible matching
members and any remaining
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
are ignored.
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-read-preference-tag-order-matching">
Order of Tag Matching
<!-- -->
.
</a>
</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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
readPreference
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.readPreference" 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-urioption-urioption.readPreference">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
read preferences
</a>
for this connection. Possible values 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/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
(
<em>
Default
</em>
)
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primaryPreferred">
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondaryPreferred">
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-nearest">
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</a>
</p>
</li>
</ul>
<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="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
. All
operations in a given transaction must route to the same member.
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
</a>
shell. 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>
instead.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.maxStalenessSeconds" 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-urioption-urioption.maxStalenessSeconds">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies, in seconds, how stale a secondary can be before the client
stops using it for read operations. For details, see
<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>
<p class="leafygreen-ui-1kp3ins">
By default, there is no maximum staleness and clients will not consider a
secondary's lag when choosing where to direct a read operation.
</p>
<p class="leafygreen-ui-1kp3ins">
The minimum
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.maxStalenessSeconds" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
</span>
</a>
value is 90
seconds. Specifying a value between 0 and 90 seconds will produce
an error. MongoDB drivers treat a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value
of
<code class="leafygreen-ui-1l06pbn">
-1
</code>
as "no max staleness", the same as if
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
is omitted.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.readPreferenceTags" 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-urioption-urioption.readPreferenceTags">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
tags document
</a>
as a comma-separated
list of colon-separated key-value pairs. For example,
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To specify the tags document
<code class="leafygreen-ui-1l06pbn">
{ "dc": "ny", "rack": "r1" }
</code>
,
use
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags=dc:ny,rack:r1
</code>
in the connection
string.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To specify an empty tags document
<code class="leafygreen-ui-1l06pbn">
{ }
</code>
, use
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags=
</code>
without setting the value.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To specify a
<em>
list
</em>
of tag documents, use multiple
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
. For example,
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Order matters when using multiple
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
. The
<code class="leafygreen-ui-1l06pbn">
readPreferenceTags
</code>
are tried in order until a match is
found. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-read-preference-tag-order-matching">
Order of Tag Matching
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
This connection string option is not available for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
</a>
shell. 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>
instead.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
Read preferences
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-connection-string-auth-options">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Authentication Options
<a class="headerlink leafygreen-ui-1kepx47" href="#authentication-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="authentication-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following connection string to a replica set specifies the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
to the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database. That is, the user
credentials are authenticated 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":"mongodb://myDatabaseUser:D1fficultP%[email protected]:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl&authSource=admin","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">mongodb:/<!-- -->/my<!-- -->DatabaseUser:D1fficultP%[email protected]:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl&authSource=admin</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 username or password includes the following characters, those
characters must be converted using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc3986#section-2.1" rel="noopener noreferrer">
<span>
percent encoding
<!-- -->
:
</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"$ : / ? # [ ] @"}
</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">$ : / ? # [ ] @</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.authSource" 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-urioption-urioption.authSource">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify the database name associated with the user's
credentials. If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
is unspecified,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
defaults to the
<code class="leafygreen-ui-1l06pbn">
defaultauthdb
</code>
specified in the connection string. If
<code class="leafygreen-ui-1l06pbn">
defaultauthdb
</code>
is
unspecified, then
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
defaults to
<code class="leafygreen-ui-1l06pbn">
admin
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
PLAIN
</code>
(LDAP),
<code class="leafygreen-ui-1l06pbn">
GSSAPI
</code>
(Kerberos), and
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
(IAM) authentication mechanisms require that
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
be set to
<code class="leafygreen-ui-1l06pbn">
$external
</code>
, as these
mechanisms delegate credential storage to external services.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB will ignore
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
values if no username
is provided, either in the connection string or via the
<code class="leafygreen-ui-1l06pbn">
--username
</code>
parameter.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
authMechanism
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.authMechanism" 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-urioption-urioption.authMechanism">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Default: SCRAM-SHA-256
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify the authentication mechanism that MongoDB uses to
authenticate the connection. If you don't specify an
<code class="leafygreen-ui-1l06pbn">
authMechanism
</code>
but provide user credentials, MongoDB attempts
to use SCRAM-SHA-256. If this fails, it falls back to
SCRAM-SHA-1.
</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-sha-1">
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-sha-256">
SCRAM-SHA-256
</a>
</p>
</li>
<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>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
(Kerberos)
</p>
</li>
<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>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
MONGODB-OIDC
</code>
(OpenID Connect OIDC), you must also set the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authMechanismProperties" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authMechanismProperties
</code>
</span>
</a>
<code class="leafygreen-ui-1l06pbn">
ENVIRONMENT
</code>
variable
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Only MongoDB Enterprise
<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 provide
<code class="leafygreen-ui-1l06pbn">
GSSAPI
</code>
(Kerberos) and
<code class="leafygreen-ui-1l06pbn">
PLAIN
</code>
(LDAP) mechanisms.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<code class="leafygreen-ui-1l06pbn">
MONGODB-X509
</code>
, you must have TLS/SSL Enabled.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
, you must be connecting to a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/atlas/database?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
cluster
which has been configured to support authentication via
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html" rel="noopener noreferrer">
<span>
AWS IAM credentials
</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>
(an AWS access key ID and a secret access key, and
optionally an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html" rel="noopener noreferrer">
<span>
AWS session token
</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>
).
The
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
authentication mechanism requires that the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authSource" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authSource
</code>
</span>
</a>
be set to
<code class="leafygreen-ui-1l06pbn">
$external
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
When using
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
, provide your AWS access key ID as the
username and the secret access key as the password. If using an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html" rel="noopener noreferrer">
<span>
AWS session token
</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>
as well, provide it with the
<code class="leafygreen-ui-1l06pbn">
AWS_SESSION_TOKEN
</code>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authMechanismProperties" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authMechanismProperties
</code>
</span>
</a>
value.
</p>
<p class="leafygreen-ui-1kp3ins">
If the AWS access key ID, the secret access key, or the session token
include the following characters, those characters must be converted using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc3986#section-2.1" rel="noopener noreferrer">
<span>
percent encoding
<!-- -->
.
</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"$ : / ? # [ ] @"}
</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">$ : / ? # [ ] @</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Alternatively, if the AWS access key ID, secret access key, or
session token are defined on your platform using their respective
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html#envvars-list" rel="noopener noreferrer">
<span>
AWS IAM environment variables
</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>
<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>
will use these environment
variable values to authenticate; you do not need to specify them
in the connection string.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-examples/#std-label-connections-string-example-mongodb-aws">
Connect to an Atlas Cluster
</a>
for example usage of
the
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
authentication mechanism using both a
connection string and the environment variables method.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/">
Authentication on Self-Managed Deployments
</a>
for more information about the
authentication system in MongoDB. Also consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-client-authentication/">
Use x.509 Certificates to Authenticate Clients on Self-Managed Deployments
</a>
for more
information on x509 authentication.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
authMechanismProperties
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.authMechanismProperties" 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-urioption-urioption.authMechanismProperties">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify properties for the specified
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authMechanism" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authMechanism
</code>
</span>
</a>
as a comma-separated list of colon-separated key-value pairs.
</p>
<p class="leafygreen-ui-1kp3ins">
Possible key-value pairs are:
</p>
<dl>
<dt>
<code class="leafygreen-ui-1l06pbn">
SERVICE_NAME:<string>
</code>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Set the Kerberos service name when connecting to Kerberized
MongoDB instances. This value must match the service name set
on MongoDB instances to which you are connecting. Only valid
when using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
authentication mechanism.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
SERVICE_NAME
</code>
defaults to
<code class="leafygreen-ui-1l06pbn">
mongodb
</code>
for all clients and
MongoDB instances. If you change the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.saslServiceName">
<code class="leafygreen-ui-1l06pbn">
saslServiceName
</code>
</a>
setting on a MongoDB instance, you
must set
<code class="leafygreen-ui-1l06pbn">
SERVICE_NAME
</code>
to match that setting. Only valid
when using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
authentication mechanism.
</p>
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
CANONICALIZE_HOST_NAME:true|false
</code>
</dt>
<dd class="css-1ufxuu7">
Canonicalize the hostname of the client host machine when
connecting to the Kerberos server. This may be required when
hosts report different hostnames than what is in the Kerberos
database. Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
. Only valid when using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
authentication
mechanism.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
SERVICE_REALM:<string>
</code>
</dt>
<dd class="css-1ufxuu7">
Set the Kerberos realm for the MongoDB service. This may be
necessary to support cross-realm authentication where the user
exists in one realm and the service in another. Only valid when
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-security-auth-kerberos">
GSSAPI
</a>
authentication
mechanism.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
AWS_SESSION_TOKEN:<security_token>
</code>
</dt>
<dd class="css-1ufxuu7">
Set the AWS session token for authentication with temporary
credentials when using an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html" rel="noopener noreferrer">
<span>
AssumeRole
</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>
request, or when working with AWS resources that specify this
value such as Lambda. Only valid when using the
<code class="leafygreen-ui-1l06pbn">
MONGODB-AWS
</code>
authentication mechanism. You must have an AWS access key ID
and a secret access key as well. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/connection-string-examples/#std-label-connections-string-example-mongodb-aws">
Connect to an Atlas Cluster
</a>
for example usage.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
ENVIRONMENT:<string>
</code>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Set the OpenID Connect (OIDC) environment. For:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Microsoft Azure, set
<code class="leafygreen-ui-1l06pbn">
ENVIRONMENT:azure
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Google Cloud Platform, set
<code class="leafygreen-ui-1l06pbn">
ENVIRONMENT:gcp
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You must also set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authMechanism" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authMechanism
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
MONGODB-OIDC
</code>
.
</p>
</dd>
</dl>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
gssapiServiceName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.gssapiServiceName" 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-urioption-urioption.gssapiServiceName">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Set the Kerberos service name when connecting to Kerberized
MongoDB instances. This value must match the service name set on
MongoDB instances to which you are connecting.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.gssapiServiceName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
gssapiServiceName
</code>
</span>
</a>
defaults to
<code class="leafygreen-ui-1l06pbn">
mongodb
</code>
for all
clients and MongoDB instances. If you change
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.saslServiceName">
<code class="leafygreen-ui-1l06pbn">
saslServiceName
</code>
</a>
setting on a MongoDB instance, you
must set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.gssapiServiceName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
gssapiServiceName
</code>
</span>
</a>
to match that setting.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.gssapiServiceName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
gssapiServiceName
</code>
</span>
</a>
is a deprecated aliases for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.authMechanismProperties" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
authMechanismProperties=SERVICE_NAME:mongodb
</code>
</span>
</a>
. For more information on which
options your driver supports and their relative priority to each
other, reference the documentation for your preferred driver
version.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-selection-discovery-options">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Server Selection and Discovery Options
<a class="headerlink leafygreen-ui-1kepx47" href="#server-selection-and-discovery-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="server-selection-and-discovery-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides the following options to configure how MongoDB drivers
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 select a server to which to direct read
or write operations.
</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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
localThresholdMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.localThresholdMS" 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-urioption-urioption.localThresholdMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The size (in milliseconds) of the latency window for selecting
among multiple suitable MongoDB instances.
<em>
Default
</em>
: 15
milliseconds.
</p>
<p class="leafygreen-ui-1kp3ins">
All drivers use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.localThresholdMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
localThresholdMS
</code>
</span>
</a>
. Use the
<code class="leafygreen-ui-1l06pbn">
localThreshold
</code>
alias when specifying the latency window size
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
serverSelectionTimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.serverSelectionTimeoutMS" 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-urioption-urioption.serverSelectionTimeoutMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies how long (in milliseconds) to block for server
selection before throwing an exception.
<em>
Default
</em>
: 30,000
milliseconds.
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
serverSelectionTryOnce
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.serverSelectionTryOnce" 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-urioption-urioption.serverSelectionTryOnce">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<strong>
Single-threaded drivers only
</strong>
. When
<code class="leafygreen-ui-1l06pbn">
true
</code>
, instructs the
driver to scan the MongoDB deployment exactly once after server
selection fails and then either select a server or raise an
error. When
<code class="leafygreen-ui-1l06pbn">
false
</code>
, the driver blocks and searches for a
server up to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.serverSelectionTimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
serverSelectionTimeoutMS
</code>
</span>
</a>
value.
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Multi-threaded drivers and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
do not support
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.serverSelectionTryOnce" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
serverSelectionTryOnce
</code>
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
heartbeatFrequencyMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.heartbeatFrequencyMS" 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-urioption-urioption.heartbeatFrequencyMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.heartbeatFrequencyMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
heartbeatFrequencyMS
</code>
</span>
</a>
controls when the driver
checks the state of the MongoDB deployment. Specify the interval
(in milliseconds) between checks, counted from the end of the
previous check until the beginning of the next one.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Single-threaded drivers: 60 seconds.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Multi-threaded drivers: 10 seconds.
</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>
does not support changing the frequency of
the heartbeat checks.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
socketCheckIntervalMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.socketCheckIntervalMS" 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-urioption-urioption.socketCheckIntervalMS">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<strong>
Single-threaded clients only
</strong>
. Controls how often the client checks the
state of the TCP connection to the MongoDB deployment. If you specify a lower
value, the client detects network issues faster but uses more CPU.
<em>
Default
</em>
: 5 seconds.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is not supported by all drivers. Refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Miscellaneous Configuration
<a class="headerlink leafygreen-ui-1kepx47" href="#miscellaneous-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="miscellaneous-configuration">
</div>
</a>
</h2>
<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>
Connection Option
</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>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
appName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.appName" 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-urioption-urioption.appName">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specify a custom app name. The app name appears in:
</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/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>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
logs
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-data-currentOp.appName">
<code class="leafygreen-ui-1l06pbn">
currentOp.appName
</code>
</a>
field in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
command and
<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>
method output
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#mongodb-data-system.profile.appName">
<code class="leafygreen-ui-1l06pbn">
system.profile.appName
</code>
</a>
field in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
database profiler
</a>
output
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.appName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
appName
</code>
</span>
</a>
connection option is available for:
</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/drivers/" target="_self">
<span>
MongoDB Drivers
</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/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
starting in
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
1.1.9
</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/" target="_self">
<span>
MongoDB Compass
</span>
</a>
starting in Compass 1.28.4
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
retryReads
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.retryReads" 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-urioption-urioption.retryReads">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Enables
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-reads/#std-label-retryable-reads">
retryable reads
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
. Enables retryable reads for the connection.
</p>
<p class="leafygreen-ui-1kp3ins">
Official MongoDB drivers default to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
. Disables retryable reads for the connection.
</p>
</li>
</ul>
<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>
does not support retryable reads.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
retryWrites
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.retryWrites" 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-urioption-urioption.retryWrites">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Enable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/#std-label-retryable-writes">
retryable writes
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
. Enables retryable writes for the connection.
</p>
<p class="leafygreen-ui-1kp3ins">
Official MongoDB drivers default to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
. Disables retryable writes for the connection.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
MongoDB drivers retry
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transactions-retry">
transaction commit and abort operations
</a>
regardless of the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.retryWrites" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
retryWrites
</code>
</span>
</a>
. For more
information on transaction retryability, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transactions-retry">
Transaction Error Handling
<!-- -->
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
uuidRepresentation
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.uuidRepresentation" 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-urioption-urioption.uuidRepresentation">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<dl>
<dt>
<code class="leafygreen-ui-1l06pbn">
standard
</code>
</dt>
<dd class="css-1ufxuu7">
The standard binary representation.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
csharpLegacy
</code>
</dt>
<dd class="css-1ufxuu7">
The default representation for the C# driver.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
javaLegacy
</code>
</dt>
<dd class="css-1ufxuu7">
The default representation for the Java driver.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
pythonLegacy
</code>
</dt>
<dd class="css-1ufxuu7">
The default representation for the Python driver.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
For the default, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
</span>
</a>
documentation for your driver.
</p>
<p class="leafygreen-ui-1kp3ins">
Not all drivers support the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.uuidRepresentation" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
uuidRepresentation
</code>
</span>
</a>
option. For information on your driver, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
drivers
</span>
</a>
documentation.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
loadBalanced
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.loadBalanced" 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-urioption-urioption.loadBalanced">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies whether the client is connecting to a load balancer. This option is
<code class="leafygreen-ui-1l06pbn">
false
</code>
by default.
</p>
<p class="leafygreen-ui-1kp3ins">
You can set this option to
<code class="leafygreen-ui-1l06pbn">
true
</code>
only if you meet the following
requirements:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You specify only one host name.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You aren't connecting to a replica set.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.srvMaxHosts" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
srvMaxHosts
</code>
</span>
</a>
option is unset or has a value of
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-urioption-urioption.directConnection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
directConnection
</code>
</span>
</a>
option is unset or has a value of
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<dl class="urioption">
<dt>
<code class="leafygreen-ui-1l06pbn">
srvMaxHosts
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-urioption-urioption.srvMaxHosts" 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-urioption-urioption.srvMaxHosts">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies the number of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
connections that can be created for
sharded topologies. Set this option to a non-negative integer.
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the default value and means there is no limit on the number of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
connections.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/read-preference-staleness/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Read Preference
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#read-preference-maxstalenessseconds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-maxstalenessseconds">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
Replica set members can lag behind the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
due to network
congestion, low disk throughput, long-running operations, etc. The read
preference
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
option lets you specify a maximum
replication lag, or "staleness", for reads from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondaries
</a>
. When a secondary's estimated staleness exceeds
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
, the client stops using it for read operations.
</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
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
read preference option is intended for
applications that read from secondaries and want to avoid reading
from a secondary that has fallen overly far behind in replicating
the primary's writes. For example, a secondary might stop
replicating due to a network outage between itself and the primary.
In that case, the client should stop reading from the secondary
until an administrator resolves the outage and the secondary catches
up.
</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication-flow-control">
Flow control
</a>
limits the rate at which
the primary applies its writes with the goal of keeping
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
<code class="leafygreen-ui-1l06pbn">
majority
committed
</code>
</a>
lag under a
specified maximum value.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can specify
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
with the following read
preference modes:
</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/read-preference/#mongodb-readmode-primaryPreferred">
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondaryPreferred">
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-nearest">
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Max staleness is not compatible with mode
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
and only
applies when
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection">
selecting
</a>
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
member of a set for a read operation.
</p>
<p class="leafygreen-ui-1kp3ins">
When selecting a server for a read operation with
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
, clients
estimate how stale each secondary is by comparing the secondary's last
write to that of the primary. The client will then direct 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">
If there is no primary, the client uses the secondary with the most
recent write for the comparison.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, there is no maximum staleness and clients will not consider a
secondary's lag when choosing where to direct a read operation.
</p>
<p class="leafygreen-ui-1kp3ins">
You must specify a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value of 90 seconds or
longer: specifying a smaller
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value will raise
an error. Clients estimate secondaries' staleness by periodically
checking the latest write date of each replica set member. Since these
checks are infrequent, the staleness estimate is coarse. Thus, clients
cannot enforce a
<code class="leafygreen-ui-1l06pbn">
maxStalenessSeconds
</code>
value of less than 90 seconds.
</p>
</section>
|
https://www.mongodb.com/docs/manual/core/read-preference-hedge-option/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Hedged Read Option
<a class="headerlink leafygreen-ui-1kepx47" href="#hedged-read-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="hedged-read-option">
</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-hedged-reads" target="_self">
<span>
Enable Hedged Reads
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self">
<span>
Additional Information
</span>
</a>
</li>
</ul>
</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">
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>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can specify the use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-mongos-hedged-reads">
hedged reads
</a>
for
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>
on sharded
clusters.
</p>
<p class="leafygreen-ui-1kp3ins">
With 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>
instances can route read
operations to two replica set members per each queried shard and return
results from the first respondent per shard.
</p>
<p class="leafygreen-ui-1kp3ins">
Hedged reads are supported for the following operations:
</p>
<table class="hlist">
<tbody>
<tr>
<td>
<ul class="simple">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count">
<code class="leafygreen-ui-1l06pbn">
count
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dataSize/#mongodb-dbcommand-dbcmd.dataSize">
<code class="leafygreen-ui-1l06pbn">
dataSize
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dbStats/#mongodb-dbcommand-dbcmd.dbStats">
<code class="leafygreen-ui-1l06pbn">
dbStats
</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>
</p>
</li>
</ul>
</td>
<td>
<ul class="simple">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/filemd5/#mongodb-dbcommand-dbcmd.filemd5">
<code class="leafygreen-ui-1l06pbn">
filemd5
</code>
</a>
</p>
</li>
<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/listCollections/#mongodb-dbcommand-dbcmd.listCollections">
<code class="leafygreen-ui-1l06pbn">
listCollections
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/listIndexes/#mongodb-dbcommand-dbcmd.listIndexes">
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheListFilters/#mongodb-dbcommand-dbcmd.planCacheListFilters">
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters
</code>
</a>
</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p class="leafygreen-ui-1kp3ins">
To specify hedged read for a read preference, use the hedged read option for
read preferences.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Enable Hedged Reads
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-hedged-reads" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-hedged-reads">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To use hedged reads, enable the hedge read option for non-
<code class="leafygreen-ui-1l06pbn">
primary
</code>
read preferences.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When using the drivers, refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
drivers' read preference API
<!-- -->
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
, you can use the helper
methods
<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>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Information
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-information">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For more information on hedged reads, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-mongos-hedged-reads">
Hedged Reads
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Member Selection with Hedged Reads
<a class="headerlink leafygreen-ui-1kepx47" href="#member-selection-with-hedged-reads" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="member-selection-with-hedged-reads">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For details on member selection for hedged reads, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-read-preference-mechanics-sharded-cluster">
Read Preference and Shards
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Hedged Reads Diagnostics
<a class="headerlink leafygreen-ui-1kepx47" href="#hedged-reads-diagnostics" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="hedged-reads-diagnostics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The command
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-dbcommand-dbcmd.serverStatus">
<code class="leafygreen-ui-1l06pbn">
serverStatus
</code>
</a>
and its corresponding
<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.serverStatus/#mongodb-method-db.serverStatus">
<code class="leafygreen-ui-1l06pbn">
db.serverStatus()
</code>
</a>
return
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.hedgingMetrics">
<code class="leafygreen-ui-1l06pbn">
hedgingMetrics
</code>
.
</a>
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/planCacheListFilters/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
planCacheListFilters
<a class="headerlink leafygreen-ui-1kepx47" href="#plancachelistfilters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="plancachelistfilters">
</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="#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">
planCacheListFilters
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.planCacheListFilters" 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.planCacheListFilters">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Lists the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
associated with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-plan-cache-query-shape">
plan cache query shapes
</a>
for a collection.
</p>
<table class="css-11h39yh e1nex8bq0">
<colgroup>
<col class="field-name"/>
<col class="field-body"/>
</colgroup>
<tbody>
<tr class="css-x8snli">
<th>
Returns
<!-- -->
:
</th>
<td>
Document listing the index filters. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-planCacheListFilters-output" target="_self">
<span>
Output
<!-- -->
.
</span>
</a>
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Settings
<a class="headerlink leafygreen-ui-1kepx47" href="#query-settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-settings">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, use query settings instead of adding
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
. Index filters are deprecated
starting in MongoDB 8.0.
</p>
<p class="leafygreen-ui-1kp3ins">
Query settings have more functionality than index filters. Also, index
filters aren't persistent and you cannot easily create index filters for
all cluster nodes. To add query settings and explore examples, 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>
</section>
</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 planCacheListFilters: <collection>\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">planCacheListFilters</span>: <<!-- -->collection<!-- -->></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: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">
planCacheListFilters
</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 collection.
</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">
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">
A user must have access that includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheIndexFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheIndexFilter
</code>
</a>
action.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-planCacheListFilters-output">
</span>
</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.planCacheListFilters" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters
</code>
</span>
</a>
command returns the document with
the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"filters\" : [\n {\n \"query\" : <query>\n \"sort\" : <sort>,\n \"projection\" : <projection>,\n \"collation\" : <collation>,\n \"indexes\" : [\n <index1>,\n ...\n ]\n },\n ...\n ],\n \"ok\" : 1\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"> "filters" : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "query" : <query></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "sort" : <sort>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "projection" : <projection>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "collation" : <collation>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "indexes" : [</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <index1>,</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"> "ok" : 1</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>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters" 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-planCacheListFilters.filters">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The array of documents that contain the index filter information.
</p>
<p class="leafygreen-ui-1kp3ins">
Each document contains the following fields:
</p>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters.query
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters.query" 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-planCacheListFilters.filters.query">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The query predicate associated with this filter. Although the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.query" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
query
</code>
</span>
</a>
shows the specific
values used to create the index filter, the values in the
predicate are insignificant; i.e. query predicates cover similar
queries that differ only in the values.
</p>
<p class="leafygreen-ui-1kp3ins">
For instance, a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.query" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
query
</code>
</span>
</a>
predicate of
<code class="leafygreen-ui-1l06pbn">
{ "type": "electronics", "status" : "A" }
</code>
covers
the following query predicates:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ type: \"food\", status: \"A\" }\n{ type: \"utensil\", status: \"D\" }","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">type</span>: <span class="lg-highlight-string">"food"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"utensil"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"D"</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>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters.sort
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters.sort" 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-planCacheListFilters.filters.sort">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The sort associated with this filter. Can be an empty document.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters.projection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters.projection" 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-planCacheListFilters.filters.projection">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The projection associated with this filter. Can be an empty
document.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters.collation
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters.collation" 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-planCacheListFilters.filters.collation">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
associated with this filter. Can
be an empty document.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.filters.indexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.filters.indexes" 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-planCacheListFilters.filters.indexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The array of indexes for the plan cache query shape.
</p>
<p class="leafygreen-ui-1kp3ins">
The plan cache query shape is the combination of these fields:
</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="#mongodb-data-planCacheListFilters.filters.query" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
query
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.sort" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sort
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.projection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
projection
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.collation" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collation
</code>
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To choose the best query plan, the query optimizer evaluates the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-planCacheListFilters.filters.indexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
indexes
</code>
</span>
</a>
<em>
and
</em>
the collection
scan.
</p>
</dd>
</dl>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters.ok
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-planCacheListFilters.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-planCacheListFilters.ok">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The status of the command.
</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">
<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/planCacheClearFilters/#mongodb-dbcommand-dbcmd.planCacheClearFilters">
<code class="leafygreen-ui-1l06pbn">
planCacheClearFilters
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheSetFilter/#mongodb-dbcommand-dbcmd.planCacheSetFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheSetFilter
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/js-client-side-field-level-encryption/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Client-Side Field Level Encryption Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#client-side-field-level-encryption-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="client-side-field-level-encryption-methods">
</div>
</a>
</h1>
<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 details on a specific method, including syntax and examples,
click on the link to the method's reference page.
</p>
</div>
</div>
<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>
<p class="leafygreen-ui-1kp3ins">
The following methods are 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>
<em>
only
</em>
. For instructions on implementing client-side field level
encryption using a MongoDB driver, defer to the driver documentation. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/compatibility/#std-label-csfle-driver-compatibility">
Client-Side Field Level Encryption Driver Compatibility
</a>
for a complete list of drivers with support
for client-side field level encryption.
</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>
Name
</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/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns the key vault object for the current MongoDB connection.
</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/KeyVault.createKey/#mongodb-method-KeyVault.createKey">
<code class="leafygreen-ui-1l06pbn">
KeyVault.createKey()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Creates a data encryption key for use with client-side field level encryption.
</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/KeyVault.deleteKey/#mongodb-method-KeyVault.deleteKey">
<code class="leafygreen-ui-1l06pbn">
KeyVault.deleteKey()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Deletes the specified data encryption key from the key vault.
</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/KeyVault.getKey/#mongodb-method-KeyVault.getKey">
<code class="leafygreen-ui-1l06pbn">
KeyVault.getKey()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Retreives the specified data encryption key from the key vault.
</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/KeyVault.getKeys/#mongodb-method-KeyVault.getKeys">
<code class="leafygreen-ui-1l06pbn">
KeyVault.getKeys()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Retrieves all keys in the key vault.
</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/KeyVault.addKeyAlternateName/#mongodb-method-KeyVault.addKeyAlternateName">
<code class="leafygreen-ui-1l06pbn">
KeyVault.addKeyAlternateName()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Associates a key alternative name to the specified data encryption key.
</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/KeyVault.removeKeyAlternateName/#mongodb-method-KeyVault.removeKeyAlternateName">
<code class="leafygreen-ui-1l06pbn">
KeyVault.removeKeyAlternateName()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Removes a key alternative name from the specified data encryption key.
</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/KeyVault.rewrapManyDataKey/#mongodb-method-KeyVault.rewrapManyDataKey">
<code class="leafygreen-ui-1l06pbn">
KeyVault.rewrapManyDataKey()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Decrypts multiple data keys and re-encrypts them with a new master key.
</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/KeyVault.getKeyByAltName/#mongodb-method-KeyVault.getKeyByAltName">
<code class="leafygreen-ui-1l06pbn">
KeyVault.getKeyByAltName()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Retrieves keys with the specified key alternative name.
</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/getClientEncryption/#mongodb-method-getClientEncryption">
<code class="leafygreen-ui-1l06pbn">
getClientEncryption()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns the client encryption object for supporting explicit encryption/decryption of fields.
</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/ClientEncryption.createEncryptedCollection/#mongodb-method-ClientEncryption.createEncryptedCollection">
<code class="leafygreen-ui-1l06pbn">
ClientEncryption.createEncryptedCollection()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Creates a collection with encrypted fields.
</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/ClientEncryption.encrypt/#mongodb-method-ClientEncryption.encrypt">
<code class="leafygreen-ui-1l06pbn">
ClientEncryption.encrypt()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Encrypts a field using a specified data encryption key and encryption algorithm.
</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/ClientEncryption.decrypt/#mongodb-method-ClientEncryption.decrypt">
<code class="leafygreen-ui-1l06pbn">
ClientEncryption.decrypt()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Decrypts a field using the associated data encryption key and encryption algorithm.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/query/not/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$not
<a class="headerlink leafygreen-ui-1kepx47" href="#-not" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-not">
</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>
</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">
$not
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-not" 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.-not">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-not" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$not
</code>
</span>
</a>
performs a logical
<code class="leafygreen-ui-1l06pbn">
NOT
</code>
operation on the
specified
<code class="leafygreen-ui-1l06pbn">
<operator-expression>
</code>
and selects the documents that
do
<em>
not
</em>
match the
<code class="leafygreen-ui-1l06pbn">
<operator-expression>
</code>
. This includes
documents that do not contain the
<code class="leafygreen-ui-1l06pbn">
field
</code>
.
</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">
$not
</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-query-op.-not" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$not
</code>
</span>
</a>
operator has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ field: { $not: { <operator-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">field</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <!-- -->{ <<!-- -->operator<!-- -->-<!-- -->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">
Consider the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { price: { $not: { $gt: 1.99 } } } )","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">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">price</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">1.99</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 query will select all documents in the
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection where:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<code class="leafygreen-ui-1l06pbn">
price
</code>
field value is less than or equal to
<code class="leafygreen-ui-1l06pbn">
1.99
</code>
<strong>
or
</strong>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<code class="leafygreen-ui-1l06pbn">
price
</code>
field does not exist
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ $not: { $gt: 1.99 } }
</code>
is different from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/lte/#mongodb-query-op.-lte">
<code class="leafygreen-ui-1l06pbn">
$lte
</code>
</a>
operator.
<code class="leafygreen-ui-1l06pbn">
{ $lte: 1.99 }
</code>
returns
<em>
only
</em>
the documents where
<code class="leafygreen-ui-1l06pbn">
price
</code>
field exists and its value is less than or equal to
<code class="leafygreen-ui-1l06pbn">
1.99
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You must use the
<code class="leafygreen-ui-1l06pbn">
$not
</code>
operator with another operator expression. For
example, to use
<code class="leafygreen-ui-1l06pbn">
$not
</code>
to perform an inequality check, use this
syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ price: { $not: { $eq: 1.99 } } }","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">price</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <span class="lg-highlight-number">1.99</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 preceding query is equivalent to:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ price: { $ne: 1.99 } }","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">price</span>: <!-- -->{ <span class="lg-highlight-attr">$ne</span>: <span class="lg-highlight-number">1.99</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
<code class="leafygreen-ui-1l06pbn">
$not
</code>
query is
<strong>
invalid
</strong>
because it attempts to
compare a field without an operator:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ price: { $not: 1.99 } }","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">price</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <span class="lg-highlight-number">1.99</span> } }</td></tr></tbody></table></code></pre>
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Arrays
<a class="headerlink leafygreen-ui-1kepx47" href="#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="arrays">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When passed an array argument, the
<code class="leafygreen-ui-1l06pbn">
$not
</code>
operator may yield
unexpected results. To match documents based on multiple false
conditions, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/nor/#mongodb-query-op.-nor">
<code class="leafygreen-ui-1l06pbn">
$nor
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Regular Expressions
<a class="headerlink leafygreen-ui-1kepx47" href="#regular-expressions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="regular-expressions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-not" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$not
</code>
</span>
</a>
operator can perform logical
<code class="leafygreen-ui-1l06pbn">
NOT
</code>
operation on:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Regular expression objects (i.e.
<code class="leafygreen-ui-1l06pbn">
/pattern/
</code>
)
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following query selects all documents in the
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection where the
<code class="leafygreen-ui-1l06pbn">
item
</code>
field value does
<em>
not
</em>
start with the letter
<code class="leafygreen-ui-1l06pbn">
p
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { item: { $not: /^p.*/ } } )","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">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <span class="lg-highlight-regexp">/^p.*/</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
</a>
operator expression
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following query selects all documents in the
<code class="leafygreen-ui-1l06pbn">
inventory
</code>
collection where the
<code class="leafygreen-ui-1l06pbn">
item
</code>
field value does
<em>
not
</em>
start with the letter
<code class="leafygreen-ui-1l06pbn">
p
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.find( { item: { $not: { $regex: \"^p.*\" } } } )\ndb.inventory.find( { item: { $not: { $regex: /^p.*/ } } } )","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">find</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <!-- -->{ <span class="lg-highlight-attr">$regex</span>: <span class="lg-highlight-string">"^p.*"</span> } } } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">inventory</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <!-- -->{ <span class="lg-highlight-attr">$not</span>: <!-- -->{ <span class="lg-highlight-attr">$regex</span>: <span class="lg-highlight-regexp">/^p.*/</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">
driver language's regular expression objects
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://pymongo.readthedocs.io/en/stable/index.html" rel="noopener noreferrer">
<span>
PyMongo
</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>
query uses
Python's
<code class="leafygreen-ui-1l06pbn">
re.compile()
</code>
method to compile a regular expression:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"import re\nfor noMatch in db.inventory.find( { \"item\": { \"$not\": re.compile(\"^p.*\") } } ):\n print noMatch","programmingLanguage":"Python"}
</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 python leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">import</span> re</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-keyword">for</span> noMatch <span class="lg-highlight-keyword">in</span> db.inventory.find( { <span class="lg-highlight-string">"item"</span>: { <span class="lg-highlight-string">"$not"</span>: re.<span class="lg-highlight-built_in">compile</span>(<span class="lg-highlight-string">"^p.*"</span>) } } ):</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-built_in">print</span> noMatch</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
<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.find/#mongodb-method-db.collection.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/operator/update/set/#mongodb-update-up.-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/query/gt/#mongodb-query-op.-gt">
<code class="leafygreen-ui-1l06pbn">
$gt
</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/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/listIndexes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
listIndexes
<a class="headerlink leafygreen-ui-1kepx47" href="#listindexes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="listindexes">
</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="#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>
</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">
listIndexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.listIndexes" 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.listIndexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns information about the indexes on the specified collection. Returned
index information includes the keys and options used to create the index, as
well as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-hidden/#std-label-index-type-hidden">
hidden indexes
</a>
. You can optionally set
the batch size for the first batch of results.
</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.getIndexes/#mongodb-method-db.collection.getIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.getIndexes()
</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.runCommand (\n {\n listIndexes: \"<collection-name>\",\n cursor: { batchSize: <int> },\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-property">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">listIndexes</span>: <span class="lg-highlight-string">"<collection-name>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cursor</span>: <!-- -->{ <span class="lg-highlight-attr">batchSize</span>: <<!-- -->int<!-- -->> <!-- -->}<!-- -->,</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">
listIndexes
</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 collection.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
cursor.batchSize
</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 cursor batch size.
</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>
<p class="leafygreen-ui-1kp3ins">
Any comment set on a
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
command is inherited
by any subsequent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore">
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
</a>
commands run on the
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
cursor.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</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">
If access control is enforced, the built-in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-read">
<code class="leafygreen-ui-1l06pbn">
read
</code>
</a>
role provides the
required privileges to run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.listIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</span>
</a>
for the collections in a
database.
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Atlas Search Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#atlas-search-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="atlas-search-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
does not return information on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self">
<span>
Atlas Search indexes
</span>
</a>
. Instead, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSearchIndexes/#mongodb-pipeline-pipe.-listSearchIndexes">
<code class="leafygreen-ui-1l06pbn">
$listSearchIndexes
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Client Disconnection
<a class="headerlink leafygreen-ui-1kepx47" href="#client-disconnection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-disconnection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 4.2, if the client that issued
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.listIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</span>
</a>
disconnects before the operation completes, MongoDB marks
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.listIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</span>
</a>
for termination using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killOp/#mongodb-dbcommand-dbcmd.killOp">
<code class="leafygreen-ui-1l06pbn">
killOp
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replica Set Member State Restriction
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-member-state-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="replica-set-member-state-restriction">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To run on a replica set member,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.listIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</span>
</a>
operations require the member
to be in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state. If the member
is in another state, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
<code class="leafygreen-ui-1l06pbn">
STARTUP2
</code>
</a>
, the
operation errors.
</p>
</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>
<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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.listIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
listIndexes
</code>
</span>
</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>
<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>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
listIndexes.cursor
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-listIndexes.cursor" 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-listIndexes.cursor">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A result set returned in the batch size specified by your cursor.
Each document in the batch output contains the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:15%"/>
<col style="width:30%"/>
</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>
id
</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>
A 64-bit integer. If zero, there are no more batches of information.
If non-zero, a cursor ID, usable in a
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
command to get the
next batch of index information.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ns
</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 database and collection name in the following format:
<code class="leafygreen-ui-1l06pbn">
<database-name>.<collection-name>
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
firstBatch
</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">
Index information includes the keys and options used to create the
index. The index option hidden is only present if the value is true.
</p>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore">
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
</a>
to retrieve additional results as needed.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
listIndexes.ok
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-listIndexes.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-listIndexes.ok">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The return value for the command. A value of
<code class="leafygreen-ui-1l06pbn">
1
</code>
indicates success.
</p>
</dd>
</dl>
</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">
List Database Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#list-database-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="list-database-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This example lists indexes for the
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
collection without specifying the
cursor batch size.
</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 (\n {\n listIndexes: \"contacts\"\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-ukaj9n">1</td><td class="leafygreen-ui-7razhx">db.runCommand (</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">2</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">3</td><td class="leafygreen-ui-7razhx"> listIndexes<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"contacts"</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">4</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">5</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>
<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.contacts',\n firstBatch: [\n { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' },\n { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' }\n ]\n },\n ok: 1\n}"}
</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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-1uztkne">1</td><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">2</td><td class="leafygreen-ui-7razhx"> cursor: {</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">3</td><td class="leafygreen-ui-7razhx"> id: Long("0"),</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">4</td><td class="leafygreen-ui-7razhx"> ns: 'test.contacts',</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">5</td><td class="leafygreen-ui-7razhx"> firstBatch: [</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">6</td><td class="leafygreen-ui-7razhx"> { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' },</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">7</td><td class="leafygreen-ui-7razhx"> { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' }</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">8</td><td class="leafygreen-ui-7razhx"> ]</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">9</td><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">10</td><td class="leafygreen-ui-7razhx"> ok: 1</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">11</td><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify Result Batch Size
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-result-batch-size" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-result-batch-size">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This example lists indexes for the
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
collection, and specifies a cursor
batch size of 1.
</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 (\n {\n listIndexes: \"contacts\", cursor: { batchSize: 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-ukaj9n">1</td><td class="leafygreen-ui-7razhx">db.runCommand (</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">2</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">3</td><td class="leafygreen-ui-7razhx"> listIndexes<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"contacts"</span><span class="lg-highlight-punctuation">,</span> cursor<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-punctuation">{</span> batchSize<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-ukaj9n">4</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">5</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>
<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(\"4809221676960028307\"),\n ns: 'test.contacts',\n firstBatch: [ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' } ]\n },\n ok: 1\n}"}
</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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-1uztkne">1</td><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">2</td><td class="leafygreen-ui-7razhx"> cursor: {</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">3</td><td class="leafygreen-ui-7razhx"> id: Long("4809221676960028307"),</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">4</td><td class="leafygreen-ui-7razhx"> ns: 'test.contacts',</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">5</td><td class="leafygreen-ui-7razhx"> firstBatch: [ { v: 2, key: { _id: 1 }, name: '_id_', ns: 'test.contacts' } ]</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">6</td><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">7</td><td class="leafygreen-ui-7razhx"> ok: 1</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">8</td><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Retrieve Additional Results
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-additional-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="retrieve-additional-results">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This example uses
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
to retrieve additional result batches from the
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
collection.
</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(\n {\n getMore: Long(\"4809221676960028307\"), collection: \"contacts\"\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-ukaj9n">1</td><td class="leafygreen-ui-7razhx">db.runCommand(</td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">2</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">{</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">3</td><td class="leafygreen-ui-7razhx"> getMore<span class="lg-highlight-punctuation">:</span> Long(<span class="lg-highlight-string">"4809221676960028307"</span>)<span class="lg-highlight-punctuation">,</span> collection<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"contacts"</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">4</td><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-punctuation">}</span></td></tr><tr class=""><td class="leafygreen-ui-ukaj9n">5</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>
<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 nextBatch: [ { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' } ],\n id: Long(\"0\"),\n ns: 'test.contacts'\n },\n ok: 1\n}"}
</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 none leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-1uztkne">1</td><td class="leafygreen-ui-7razhx">{</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">2</td><td class="leafygreen-ui-7razhx"> cursor: {</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">3</td><td class="leafygreen-ui-7razhx"> nextBatch: [ { v: 2, key: { a: 1 }, name: 'a_1', ns: 'test.contacts' } ],</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">4</td><td class="leafygreen-ui-7razhx"> id: Long("0"),</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">5</td><td class="leafygreen-ui-7razhx"> ns: 'test.contacts'</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">6</td><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">7</td><td class="leafygreen-ui-7razhx"> ok: 1</td></tr><tr class=""><td class="leafygreen-ui-1uztkne">8</td><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/collStats/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
collStats
<a class="headerlink leafygreen-ui-1kepx47" href="#collstats" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="collstats">
</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="#example" target="_self">
<span>
Example
</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">
collStats
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.collStats" 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.collStats">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
Deprecated
<!-- -->
since version
<!-- -->
6.2
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
In versions 6.2 and later use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/collStats/#mongodb-pipeline-pipe.-collStats">
<code class="leafygreen-ui-1l06pbn">
$collStats
</code>
</a>
aggregation
stage.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
command returns a variety of storage statistics
for a given collection.
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/collStats/#mongodb-pipeline-pipe.-collStats">
<code class="leafygreen-ui-1l06pbn">
$collStats
</code>
</a>
aggregation stage instead
of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.collStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</span>
</a>
command and its
<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>
helper method
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
.
</a>
</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.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
stats()
</code>
</a>
helper method.
Specific fields in the
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
output can be accessed using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dataSize/#mongodb-method-db.collection.dataSize">
<code class="leafygreen-ui-1l06pbn">
dataSize()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.estimatedDocumentCount/#mongodb-method-db.collection.estimatedDocumentCount">
<code class="leafygreen-ui-1l06pbn">
estimatedDocumentCount()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.isCapped/#mongodb-method-db.collection.isCapped">
<code class="leafygreen-ui-1l06pbn">
isCapped()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.latencyStats/#mongodb-method-db.collection.latencyStats">
<code class="leafygreen-ui-1l06pbn">
latencyStats()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.storageSize/#mongodb-method-db.collection.storageSize">
<code class="leafygreen-ui-1l06pbn">
storageSize()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.totalIndexSize/#mongodb-method-db.collection.totalIndexSize">
<code class="leafygreen-ui-1l06pbn">
totalIndexSize()
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.totalSize/#mongodb-method-db.collection.totalSize">
<code class="leafygreen-ui-1l06pbn">
totalSize()
</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>
<p class="leafygreen-ui-1kp3ins">
To run
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.runCommand/#mongodb-method-db.runCommand">
<code class="leafygreen-ui-1l06pbn">
db.runCommand( { <command> } )
</code>
</a>
method.
</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 collStats: <string>,\n scale: <int>\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">collStats</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">scale</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>
<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 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">
collStats
</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="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
scale
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
int
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The scale factor for the various size data (with the exception of
those sizes that specify the unit of measurement in the field name). The
value defaults to 1 to return size data in bytes. To display
kilobytes rather than bytes, specify a
<code class="leafygreen-ui-1l06pbn">
scale
</code>
value of
<code class="leafygreen-ui-1l06pbn">
1024
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If you specify a non-integer scale factor, MongoDB uses the integer
part of the specified factor. For example, if you specify a scale
factor of
<code class="leafygreen-ui-1l06pbn">
1023.999
</code>
, MongoDB uses
<code class="leafygreen-ui-1l06pbn">
1023
</code>
as the scale factor.
</p>
<p class="leafygreen-ui-1kp3ins">
The scale factor rounds the affected size values to whole numbers.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</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">
Redaction
<a class="headerlink leafygreen-ui-1kepx47" href="#redaction" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="redaction">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
</a>
,
<code class="leafygreen-ui-1l06pbn">
$collStats
</code>
output redacts certain information for encrypted
collections:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The output omits
<code class="leafygreen-ui-1l06pbn">
"queryExecStats"
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The output omits
<code class="leafygreen-ui-1l06pbn">
"latencyStats"
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The output redacts
<code class="leafygreen-ui-1l06pbn">
"WiredTiger"
</code>
, if present, to include only the
<code class="leafygreen-ui-1l06pbn">
url
</code>
field.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Scaled Sizes
<a class="headerlink leafygreen-ui-1kepx47" href="#scaled-sizes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="scaled-sizes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Unless otherwise specified by the metric name (such as
<code class="leafygreen-ui-1l06pbn">
"bytes
currently in the cache"
</code>
), values related to size are displayed in
bytes and can be overridden by
<code class="leafygreen-ui-1l06pbn">
scale
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The scale factor rounds the affected size values to whole numbers.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Accuracy after Unexpected Shutdown
<a class="headerlink leafygreen-ui-1kepx47" href="#accuracy-after-unexpected-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="accuracy-after-unexpected-shutdown">
</div>
</a>
</h3>
<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
<!-- -->
statistics reported by
<code class="leafygreen-ui-1l06pbn">
collStats
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.collStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</span>
</a>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collStats-output" target="_self">
<span>
output
</span>
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.collStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</span>
</a>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collStats-output" target="_self">
<span>
output
</span>
</a>
are
estimates.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
In-Progress Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#in-progress-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="in-progress-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
includes information on indexes currently being built. For details, see:
</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="#mongodb-data-collStats.nindexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.nindexes
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexDetails" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.indexDetails
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexBuilds" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.indexBuilds
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.totalIndexSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.totalIndexSize
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexSizes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.indexSizes
</code>
</span>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replica Set Member State Restriction
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-member-state-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="replica-set-member-state-restriction">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To run on a replica set member,
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
operations require the member
to be in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state. If the member
is in another state, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
<code class="leafygreen-ui-1l06pbn">
STARTUP2
</code>
</a>
, the
operation errors.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Non-Existent Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#non-existent-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="non-existent-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you run
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
for a non-existent collection, then
depending on your database implementation,
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
might
return
<code class="leafygreen-ui-1l06pbn">
0
</code>
values in the output fields instead of returning an error.
</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.runCommand( { collStats : \"nonExistentCollection\" } )","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>( <!-- -->{ <!-- -->collStats <!-- -->: <span class="lg-highlight-string">"nonExistentCollection"</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 with
<code class="leafygreen-ui-1l06pbn">
0
</code>
values in the fields:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n ns: 'test.nonExistentCollection',\n size: 0,\n count: 0,\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">ns</span>: <span class="lg-highlight-string">'test.nonExistentCollection'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">count</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>
</div>
</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 operation runs the
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
command on the
<code class="leafygreen-ui-1l06pbn">
restaurants
</code>
collection, specifying a scale of
<code class="leafygreen-ui-1l06pbn">
1024
</code>
bytes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand( { collStats : \"restaurants\", scale: 1024 } )","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>( <!-- -->{ <!-- -->collStats <!-- -->: <span class="lg-highlight-string">"restaurants"</span>, <span class="lg-highlight-attr">scale</span>: <span class="lg-highlight-number">1024</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 document provides a representation of the
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
output. Depending on the configuration of your
collection and the storage engine, the output fields may vary.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"ns\" : <string>,\n \"size\" : <number>,\n \"timeseries\" : {\n \"bucketsNs\" : <bucketname>,\n \"bucketCount\" : <number>,\n \"avgBucketSize\" : <number>,\n \"numBucketInserts\" : <number>,\n \"numBucketUpdates\" : <number>,\n \"numBucketsOpenedDueToMetadata\" : <number>,\n \"numBucketsClosedDueToCount\" : <number>,\n \"numBucketsClosedDueToSize\" : <number>,\n \"numBucketsClosedDueToTimeForward\" : <number>,\n \"numBucketsClosedDueToTimeBackward\" : <number>,\n \"numBucketsClosedDueToMemoryThreshold\" : <number>,\n \"numCommits\" : <number>,\n \"numWaits\" : <number>,\n \"numMeasurementsCommitted\" : <number>,\n \"avgNumMeasurementsPerCommit\": <number>\n },\n \"count\" : <number>,\n \"avgObjSize\" : <number>,\n \"numOrphanDocs\" : <number>, // Available starting in MongoDB 6.0\n \"storageSize\" : <number>,\n \"freeStorageSize\" : <number>,\n \"capped\" : <boolean>,\n \"max\" : <number>,\n \"maxSize\" : <number>,\n \"wiredTiger\" : {\n \"metadata\" : {\n \"formatVersion\" : <num>\n },\n \"creationString\" : <string>\n \"type\" : <string>,\n \"uri\" : <string>,\n \"LSM\" : {\n \"bloom filter false positives\" : <number>,\n \"bloom filter hits\" : <number>,\n \"bloom filter misses\" : <number>,\n \"bloom filter pages evicted from cache\" : <number>,\n \"bloom filter pages read into cache\" : <number>,\n \"bloom filters in the LSM tree\" : <number>,\n \"total size of bloom filters\" : <number>,\n \"chunks in the LSM tree\" : <number>,\n \"highest merge generation in the LSM tree\" : <number>,\n \"queries that could have benefited from a Bloom filter that did not exist\" : <number>,\n \"sleep for LSM checkpoint throttle\" : <number>,\n \"sleep for LSM merge throttle\" : <number>\n \"total size of bloom filters\" : <number>\n },\n \"block-manager\" : {\n \"allocations requiring file extension\" : <number>,\n \"blocks allocated\" : <number>,\n \"blocks freed\" : <number>,\n \"checkpoint size\" : <number>,\n \"file allocation unit size\" : <number>,\n \"file bytes available for reuse\" : <number>,\n \"file magic number\" : <number>,\n \"file major version number\" : <number>,\n \"file size in bytes\" : <number>,\n \"minor version number\" : <number>\n },\n \"btree\" : {\n \"btree checkpoint generation\" : <number>,\n \"column-store fixed-size leaf pages\" : <number>,\n \"column-store internal pages\" : <number>,\n \"column-store variable-size RLE encoded values\" : <number>,\n \"column-store variable-size deleted values\" : <number>,\n \"column-store variable-size leaf pages\" : <number>,\n \"fixed-record size\" : <number>,\n \"maximum internal page key size\" : <number>,\n \"maximum internal page size\" : <number>,\n \"maximum leaf page key size\" : <number>,\n \"maximum leaf page size\" : <number>,\n \"maximum leaf page value size\" : <number>,\n \"maximum tree depth\" : <number>,\n \"number of key/value pairs\" : <number>,\n \"overflow pages\" : <number>,\n \"pages rewritten by compaction\" : <number>,\n \"row-store empty values\" : <number>,\n \"row-store internal pages\" : <number>,\n \"row-store leaf pages\" : <number>\n },\n \"cache\" : {\n \"bytes currently in the cache\" : <number>,\n \"bytes dirty in the cache cumulative\" : <number>,\n \"bytes read into cache\" : <number>,\n \"bytes written from cache\" : <number>,\n \"checkpoint blocked page eviction\" : <number>,\n \"data source pages selected for eviction unable to be evicted\" : <number>,\n \"eviction walk passes of a file\" : <number>,\n \"eviction walk target pages histogram - 0-9\" : <number>,\n \"eviction walk target pages histogram - 10-31\" : <number>,\n \"eviction walk target pages histogram - 128 and higher\" : <number>,\n \"eviction walk target pages histogram - 32-63\" : <number>,\n \"eviction walk target pages histogram - 64-128\" : <number>,\n \"eviction walks abandoned\" : <number>,\n \"eviction walks gave up because they restarted their walk twice\" : <number>,\n \"eviction walks gave up because they saw too many pages and found no candidates\" : <number>,\n \"eviction walks gave up because they saw too many pages and found too few candidates\" : <number>,\n \"eviction walks reached end of tree\" : <number>,\n \"eviction walks started from root of tree\" : <number>,\n \"eviction walks started from saved location in tree\" : <number>,\n \"hazard pointer blocked page eviction\" : <number>,\n \"in-memory page passed criteria to be split\" : <number>,\n \"in-memory page splits\" : <number>,\n \"internal pages evicted\" : <number>,\n \"internal pages split during eviction\" : <number>,\n \"leaf pages split during eviction\" : <number>,\n \"modified pages evicted\" : <number>,\n \"overflow pages read into cache\" : <number>,\n \"page split during eviction deepened the tree\" : <number>,\n \"page written requiring cache overflow records\" : <number>,\n \"pages read into cache\" : <number>,\n \"pages read into cache after truncate\" : <number>,\n \"pages read into cache after truncate in prepare state\" : <number>,\n \"pages read into cache requiring cache overflow entries\" : <number>,\n \"pages requested from the cache\" : <number>,\n \"pages seen by eviction walk\" : <number>,\n \"pages written from cache\" : <number>,\n \"pages written requiring in-memory restoration\" : <number>,\n \"tracked dirty bytes in the cache\" : <number>,\n \"unmodified pages evicted\" : <number>\n },\n \"cache_walk\" : {\n \"Average difference between current eviction generation when the page was last considered\" : <number>,\n \"Average on-disk page image size seen\" : <number>,\n \"Average time in cache for pages that have been visited by the eviction server\" : <number>,\n \"Average time in cache for pages that have not been visited by the eviction server\" : <number>,\n \"Clean pages currently in cache\" : <number>,\n \"Current eviction generation\" : <number>,\n \"Dirty pages currently in cache\" : <number>,\n \"Entries in the root page\" : <number>,\n \"Internal pages currently in cache\" : <number>,\n \"Leaf pages currently in cache\" : <number>,\n \"Maximum difference between current eviction generation when the page was last considered\" : <number>,\n \"Maximum page size seen\" : <number>,\n \"Minimum on-disk page image size seen\" : <number>,\n \"Number of pages never visited by eviction server\" : <number>,\n \"On-disk page image sizes smaller than a single allocation unit\" : <number>,\n \"Pages created in memory and never written\" : <number>,\n \"Pages currently queued for eviction\" : <number>,\n \"Pages that could not be queued for eviction\" : <number>,\n \"Refs skipped during cache traversal\" : <number>,\n \"Size of the root page\" : <number>,\n \"Total number of pages currently in cache\" : <number>\n },\n \"compression\" : {\n \"compressed page maximum internal page size prior to compression\" : <number>,\n \"compressed page maximum leaf page size prior to compression \" : <number>,\n \"compressed pages read\" : <number>,\n \"compressed pages written\" : <number>,\n \"page written failed to compress\" : <number>,\n \"page written was too small to compress\" : 1\n },\n \"cursor\" : {\n \"bulk loaded cursor insert calls\" : <number>,\n \"cache cursors reuse count\" : <number>,\n \"close calls that result in cache\" : <number>,\n \"create calls\" : <number>,\n \"insert calls\" : <number>,\n \"insert key and value bytes\" : <number>,\n \"modify\" : <number>,\n \"modify key and value bytes affected\" : <number>,\n \"modify value bytes modified\" : <number>,\n \"next calls\" : <number>,\n \"open cursor count\" : <number>,\n \"operation restarted\" : <number>,\n \"prev calls\" : <number>,\n \"remove calls\" : <number>,\n \"remove key bytes removed\" : <number>,\n \"reserve calls\" : <number>,\n \"reset calls\" : <number>,\n \"search calls\" : <number>,\n \"search near calls\" : <number>,\n \"truncate calls\" : <number>,\n \"update calls\" : <number>,\n \"update key and value bytes\" : <number>,\n \"update value size change\" : <num>\n },\n \"reconciliation\" : {\n \"dictionary matches\" : <number>,\n \"fast-path pages deleted\" : <number>,\n \"internal page key bytes discarded using suffix compression\" : <number>,\n \"internal page multi-block writes\" : <number>,\n \"internal-page overflow keys\" : <number>,\n \"leaf page key bytes discarded using prefix compression\" : <number>,\n \"leaf page multi-block writes\" : <number>,\n \"leaf-page overflow keys\" : <number>,\n \"maximum blocks required for a page\" : <number>,\n \"overflow values written\" : <number>,\n \"page checksum matches\" : <number>,\n \"page reconciliation calls\" : <number>,\n \"page reconciliation calls for eviction\" : <number>,\n \"pages deleted\" : <number>\n },\n \"session\" : {\n \"object compaction\" : <number>,\n },\n \"transaction\" : {\n \"update conflicts\" : <number>\n }\n },\n \"nindexes\" : <number>,\n \"indexDetails\" : {\n \"_id_\" : {\n \"metadata\" : {\n \"formatVersion\" : <number>\n },\n ...\n },\n ...\n },\n \"indexBuilds\" : [\n <string>,\n ],\n \"totalIndexSize\" : <number>,\n \"totalSize\" : <number>,\n \"indexSizes\" : {\n \"_id_\" : <number>,\n \"<indexname>\" : <number>,\n ...\n },\n \"scaleFactor\" : <number>\n \"ok\" : <number>\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">"ns"</span> <!-- -->: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timeseries"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bucketsNs"</span> <!-- -->: <<!-- -->bucketName<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bucketCount"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"avgBucketSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketInserts"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketUpdates"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsOpenedDueToMetadata"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsClosedDueToCount"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsClosedDueToSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsClosedDueToTimeForward"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsClosedDueToTimeBackward"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numBucketsClosedDueToMemoryThreshold"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numCommits"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numWaits"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numMeasurementsCommitted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"avgNumMeasurementsPerCommit"</span>: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"count"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"avgObjSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"numOrphanDocs"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Available starting in </span><span class="lg-highlight-comment">MongoDB 6.0</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"storageSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"freeStorageSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"capped"</span> <!-- -->: <<!-- -->boolean<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"max"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maxSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"wiredTiger"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"formatVersion"</span> <!-- -->: <<!-- -->num<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"creationString"</span> <!-- -->: <<!-- -->string<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type"</span> <!-- -->: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"uri"</span> <!-- -->: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"LSM"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filter false positives"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filter hits"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filter misses"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filter pages evicted from cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filter pages read into cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bloom filters in the LSM tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"total size of bloom filters"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"chunks in the LSM tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"highest merge generation in the LSM tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"queries that could have benefited from a Bloom filter that did not exist"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sleep for LSM checkpoint throttle"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sleep for LSM merge throttle"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"total size of bloom filters"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"block-manager"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"allocations requiring file extension"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"blocks allocated"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"blocks freed"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"checkpoint size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"file allocation unit size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"file bytes available for reuse"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"file magic number"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"file major version number"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"file size in bytes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"minor version number"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"btree"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"btree checkpoint generation"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"column-store fixed-size leaf pages"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"column-store internal pages"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"column-store variable-size RLE encoded values"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"column-store variable-size deleted values"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"column-store variable-size leaf pages"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fixed-record size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum internal page key size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum internal page size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum leaf page key size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum leaf page size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum leaf page value size"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum tree depth"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"number of key/value pairs"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"overflow pages"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages rewritten by compaction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"row-store empty values"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"row-store internal pages"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"row-store leaf pages"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cache"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bytes currently in the cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bytes dirty in the cache cumulative"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bytes read into cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bytes written from cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"checkpoint blocked page eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"data source pages selected for eviction unable to be evicted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk passes of a file"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk target pages histogram - 0-9"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk target pages histogram - 10-31"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk target pages histogram - 128 and higher"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk target pages histogram - 32-63"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walk target pages histogram - 64-128"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks abandoned"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks gave up because they restarted their walk twice"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks gave up because they saw too many pages and found no candidates"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks gave up because they saw too many pages and found too few candidates"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks reached end of tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks started from root of tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"eviction walks started from saved location in tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hazard pointer blocked page eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"in-memory page passed criteria to be split"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"in-memory page splits"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"internal pages evicted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"internal pages split during eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"leaf pages split during eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"modified pages evicted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"overflow pages read into cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page split during eviction deepened the tree"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page written requiring cache overflow records"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages read into cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages read into cache after truncate"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages read into cache after truncate in prepare state"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages read into cache requiring cache overflow entries"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages requested from the cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages seen by eviction walk"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages written from cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages written requiring in-memory restoration"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"tracked dirty bytes in the cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"unmodified pages evicted"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cache_walk"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Average difference between current eviction generation when the page was last considered"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Average on-disk page image size seen"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Average time in cache for pages that have been visited by the eviction server"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Average time in cache for pages that have not been visited by the eviction server"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Clean pages currently in cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Current eviction generation"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Dirty pages currently in cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Entries in the root page"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Internal pages currently in cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Leaf pages currently in cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Maximum difference between current eviction generation when the page was last considered"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Maximum page size seen"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Minimum on-disk page image size seen"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Number of pages never visited by eviction server"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"On-disk page image sizes smaller than a single allocation unit"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Pages created in memory and never written"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Pages currently queued for eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Pages that could not be queued for eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Refs skipped during cache traversal"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Size of the root page"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"Total number of pages currently in cache"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"compression"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"compressed page maximum internal page size prior to compression"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"compressed page maximum leaf page size prior to compression "</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"compressed pages read"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"compressed pages written"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page written failed to compress"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page written was too small to compress"</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-string">"cursor"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bulk loaded cursor insert calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"cache cursors reuse count"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"close calls that result in cache"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"create calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insert calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"insert key and value bytes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"modify"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"modify key and value bytes affected"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"modify value bytes modified"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"next calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"open cursor count"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"operation restarted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"prev calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"remove calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"remove key bytes removed"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"reserve calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"reset calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"search calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"search near calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"truncate calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"update calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"update key and value bytes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"update value size change"</span> <!-- -->: <<!-- -->num<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"reconciliation"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dictionary matches"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fast-path pages deleted"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"internal page key bytes discarded using suffix compression"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"internal page multi-block writes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"internal-page overflow keys"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"leaf page key bytes discarded using prefix compression"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"leaf page multi-block writes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"leaf-page overflow keys"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"maximum blocks required for a page"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"overflow values written"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page checksum matches"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page reconciliation calls"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"page reconciliation calls for eviction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"pages deleted"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"session"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"object compaction"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"transaction"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"update conflicts"</span> <!-- -->: <<!-- -->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"> <span class="lg-highlight-string">"nindexes"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexDetails"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id_"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"formatVersion"</span> <!-- -->: <<!-- -->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"> <!-- -->...</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexBuilds"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"totalIndexSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"totalSize"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexSizes"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"_id_"</span> <!-- -->: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<indexName>"</span> <!-- -->: <<!-- -->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"> <span class="lg-highlight-string">"scaleFactor"</span> <!-- -->: <<!-- -->number<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"ok"</span> <!-- -->: <<!-- -->number<!-- -->></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-collStats-output">
</span>
</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>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.ns
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.ns" 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-collStats.ns">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The namespace of the current collection, which follows the format
<code class="leafygreen-ui-1l06pbn">
[database].[collection]
</code>
.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.size
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.size" 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-collStats.size">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The total uncompressed size in memory of all records in a
collection. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.size" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
size
</code>
</span>
</a>
does not
include the size of any indexes associated with the collection,
which the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.totalIndexSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
totalIndexSize
</code>
</span>
</a>
field reports.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument affects this value. Data compression does not
affect this value.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.timeseries
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.timeseries" 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-collStats.timeseries">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.timeseries" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
timeseries
</code>
</span>
</a>
appears when you run the
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
command on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time series collection
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
This document contains data for internal diagnostic use.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.count
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.count" 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-collStats.count">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of objects or documents in this collection.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.avgObjSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.avgObjSize" 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-collStats.avgObjSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The average size of an object in the collection. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument does not affect this value.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.numOrphanDocs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.numOrphanDocs" 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-collStats.numOrphanDocs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
</a>
in the
collection.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
6.0
</em>
.
</p>
</div>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.storageSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.storageSize" 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-collStats.storageSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The total amount of storage allocated to this collection for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-document">
document
</a>
storage. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument affects this
value.
</p>
<p class="leafygreen-ui-1kp3ins">
If collection data is compressed (which is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerCollectionBlockCompressor">
<code class="leafygreen-ui-1l06pbn">
default for
WiredTiger
</code>
</a>
), the
storage size reflects the compressed size and may be smaller than
the value for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.size" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
collStats.size
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.storageSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storageSize
</code>
</span>
</a>
does not include index size. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.totalIndexSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
totalIndexSize
</code>
</span>
</a>
for index sizing.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.freeStorageSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.freeStorageSize" 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-collStats.freeStorageSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Unavailable for the In-Memory Storage Engine
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The amount of storage available for reuse. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument
affects this value.
</p>
<p class="leafygreen-ui-1kp3ins">
The field is only available if storage is available for reuse (i.e.
greater than zero).
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.nindexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.nindexes" 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-collStats.nindexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of indexes on the collection. All collections have at
least one index on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-_id">
_id
</a>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.nindexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nindexes
</code>
</span>
</a>
includes indexes currently being built in
its count.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.indexDetails
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.indexDetails" 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-collStats.indexDetails">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A document that reports data from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredTiger">
WiredTiger
</a>
storage engine for each index in the collection. Other storage engines will
return an empty document.
</p>
<p class="leafygreen-ui-1kp3ins">
The fields in this document are the names of the indexes, while the
values themselves are documents that contain statistics for the
index provided by the storage engine. These statistics are for
internal diagnostic use.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexDetails" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
indexDetails
</code>
</span>
</a>
includes
details on indexes currently being built.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.indexBuilds
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.indexBuilds" 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-collStats.indexBuilds">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
An array that contains the names of the indexes that are currently
being built on the collection. Once an index build completes, the
index does not appear in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexBuilds" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
indexBuilds
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.totalIndexSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.totalIndexSize" 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-collStats.totalIndexSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Sum of the disk space used by all indexes. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument
affects this value.
</p>
<p class="leafygreen-ui-1kp3ins">
If an index uses prefix compression (which is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerIndexPrefixCompression">
<code class="leafygreen-ui-1l06pbn">
default
for WiredTiger
</code>
</a>
), the
returned size reflects the compressed size for any such indexes when
calculating the total.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.totalIndexSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
totalIndexSize
</code>
</span>
</a>
includes indexes currently being
built in the total size.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.totalSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.totalSize" 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-collStats.totalSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The sum of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.storageSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storageSize
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.totalIndexSize" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
totalIndexSize
</code>
</span>
</a>
. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument affects
this value.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.indexSizes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.indexSizes" 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-collStats.indexSizes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
This field specifies the key and size of every existing index on
the collection. The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
argument affects this value.
</p>
<p class="leafygreen-ui-1kp3ins">
If an index uses prefix compression (which is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerIndexPrefixCompression">
<code class="leafygreen-ui-1l06pbn">
default
for WiredTiger
</code>
</a>
), the
returned size reflects the compressed size.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.indexSizes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
indexSizes
</code>
</span>
</a>
includes the sizes of indexes currently being built.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.scaleFactor
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.scaleFactor" 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-collStats.scaleFactor">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
scale
</code>
value used by the command.
</p>
<p class="leafygreen-ui-1kp3ins">
If you had specified a non-integer scale factor, MongoDB uses the
integer part of the specified factor. For example, if you specify a
scale factor of
<code class="leafygreen-ui-1l06pbn">
1023.999
</code>
, MongoDB uses
<code class="leafygreen-ui-1l06pbn">
1023
</code>
as the scale
factor.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.capped
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.capped" 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-collStats.capped">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
This field will be "true" if the collection is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-capped-collection">
capped
<!-- -->
.
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.max
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.max" 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-collStats.max">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Shows the maximum number of documents that may be present in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-capped-collection">
capped collection
<!-- -->
.
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.maxSize
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.maxSize" 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-collStats.maxSize">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Shows the maximum size of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-capped-collection">
capped collection
<!-- -->
.
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.wiredTiger
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.wiredTiger" 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-collStats.wiredTiger">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.wiredTiger" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
wiredTiger
</code>
</span>
</a>
only appears when using the
WiredTiger storage engine. When using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
</a>
, WiredTiger data is redacted to only the
<code class="leafygreen-ui-1l06pbn">
url
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
This document contains data reported
directly by the WiredTiger engine and other data for internal
diagnostic use.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
collStats.inMemory
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-collStats.inMemory" 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-collStats.inMemory">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-collStats.inMemory" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
inMemory
</code>
</span>
</a>
only appears when using the in-memory
storage engine.
</p>
<p class="leafygreen-ui-1kp3ins">
This document contains data reported
directly by the storage engine and other data for internal
diagnostic use.
</p>
</dd>
</dl>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/transactions-production-consideration/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Production Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#production-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="production-considerations">
</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="#availability" target="_self">
<span>
Availability
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#feature-compatibility" target="_self">
<span>
Feature Compatibility
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#runtime-limit" target="_self">
<span>
Runtime Limit
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#oplog-size-limit" target="_self">
<span>
Oplog Size Limit
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#wiredtiger-cache" target="_self">
<span>
WiredTiger Cache
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#transactions-and-security" target="_self">
<span>
Transactions and Security
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#shard-configuration-restriction" target="_self">
<span>
Shard Configuration Restriction
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharded-clusters-and-arbiters" target="_self">
<span>
Sharded Clusters and Arbiters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#acquiring-locks" target="_self">
<span>
Acquiring Locks
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#pending-ddl-operations-and-transactions" target="_self">
<span>
Pending DDL Operations and Transactions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#in-progress-transactions-and-write-conflicts" target="_self">
<span>
In-progress Transactions and Write Conflicts
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#in-progress-transactions-and-stale-reads" target="_self">
<span>
In-progress Transactions and Stale Reads
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#in-progress-transactions-and-chunk-migration" target="_self">
<span>
In-progress Transactions and Chunk Migration
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#outside-reads-during-commit" target="_self">
<span>
Outside Reads During Commit
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self">
<span>
Additional Information
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The following page lists some production considerations for running
transactions. These apply whether you run transactions on replica sets
or sharded clusters. For running transactions on sharded clusters, see
also the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-sharded-clusters/">
Production Considerations (Sharded Clusters)
</a>
for additional
considerations that are specific to sharded clusters.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Availability
<a class="headerlink leafygreen-ui-1kepx47" href="#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="availability">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB supports multi-document transactions on replica sets.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Distributed transactions add support for multi-document transactions on
sharded clusters and incorporates the existing support for
multi-document transactions on replica sets.
</p>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Distributed Transactions and Multi-Document Transactions
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The two terms are synonymous. Distributed transactions refer to
multi-document transactions on sharded clusters and replica sets.
Multi-document transactions (whether on sharded clusters or replica sets) are
also known as distributed transactions.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Feature Compatibility
<a class="headerlink leafygreen-ui-1kepx47" href="#feature-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="feature-compatibility">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To use transactions, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion
</a>
for all members of the deployment must be at least:
</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>
Deployment
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Minimum
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Replica Set
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
4.0
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Sharded Cluster
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
4.2
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
To check the fCV for a member, connect to the member 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( { 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">
For more information, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
reference page.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-transaction-limit">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Runtime Limit
<a class="headerlink leafygreen-ui-1kepx47" href="#runtime-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="runtime-limit">
</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 configure maximum transaction lifetimes in MongoDB Atlas,
see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/cluster-additional-settings/#set-transaction-lifetime" target="_self">
<span>
Set Transaction Lifetime
</span>
</a>
in the Atlas documentation.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
By default, a transaction must have a runtime of less than one minute.
You can modify this limit using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds">
<code class="leafygreen-ui-1l06pbn">
transactionLifetimeLimitSeconds
</code>
</a>
for 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. For sharded clusters, the parameter
must be modified for all shard replica set members. Transactions that
exceeds this limit are considered expired and will be aborted by a
periodic cleanup process.
</p>
<p class="leafygreen-ui-1kp3ins">
For sharded clusters, you can also specify a
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
limit on
<code class="leafygreen-ui-1l06pbn">
commitTransaction
</code>
. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-sharded-clusters/#std-label-transactions-sharded-clusters-time-limit">
Sharded Clusters
Transactions Time Limit
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-txn-oplog-size-limit">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Oplog Size Limit
<a class="headerlink leafygreen-ui-1kepx47" href="#oplog-size-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="oplog-size-limit">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB creates as many oplog entries as necessary to the encapsulate all write
operations in a transaction, instead of a single entry for all write operations
in the transaction. This removes the 16MB total size limit for a transaction
imposed by the single oplog entry for all its write operations. Although the
total size limit is removed, each oplog entry still must be within the
BSON document size limit of 16MB.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
WiredTiger Cache
<a class="headerlink leafygreen-ui-1kepx47" href="#wiredtiger-cache" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-cache">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To prevent storage cache pressure from negatively impacting the
performance:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When you abandon a transaction, abort the transaction.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When you encounter an error during individual operation in the
transaction, abort and retry the transaction.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.transactionLifetimeLimitSeconds">
<code class="leafygreen-ui-1l06pbn">
transactionLifetimeLimitSeconds
</code>
</a>
also ensures that
expired transactions are aborted periodically to relieve storage cache
pressure.
</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 you have an uncommitted transaction that causes excessive pressure
on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger cache
</a>
, the transaction
aborts and returns a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-write-conflict">
write conflict
</a>
error.
</p>
<p class="leafygreen-ui-1kp3ins">
If a transaction is too large to ever fit in the WiredTiger cache,
the transaction aborts and returns a
<code class="leafygreen-ui-1l06pbn">
TransactionTooLargeForCache
</code>
error.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Transactions and Security
<a class="headerlink leafygreen-ui-1kepx47" href="#transactions-and-security" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-security">
</div>
</a>
</h2>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
access control
</a>
, you must
have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#std-label-built-in-roles">
privileges
</a>
for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-operations">
operations in the transaction
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
auditing
</a>
, operations in an
aborted transaction are still audited. However, there is no audit
event that indicates that the transaction aborted.
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-transactions-disabled-wcmajority">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Shard Configuration Restriction
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-configuration-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="shard-configuration-restriction">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You cannot run transactions on a sharded cluster that has a shard
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>
(such as a shard with a voting member that uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory
storage engine
</a>
).
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Sharded Clusters and Arbiters
<a class="headerlink leafygreen-ui-1kepx47" href="#sharded-clusters-and-arbiters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-clusters-and-arbiters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You cannot change a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
using a transaction
if the replica set has an arbiter. Arbiters cannot participate in the
data operations required for multi-shard transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
Transactions whose write operations span multiple shards will error
and abort if any transaction operation reads from or writes to a
shard that contains an arbiter.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-txns-locks">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Acquiring Locks
<a class="headerlink leafygreen-ui-1kepx47" href="#acquiring-locks" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="acquiring-locks">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
By default, transactions wait up to
<code class="leafygreen-ui-1l06pbn">
5
</code>
milliseconds to acquire locks
required by the operations in the transaction. If the transaction
cannot acquire its required locks within the
<code class="leafygreen-ui-1l06pbn">
5
</code>
milliseconds, the
transaction aborts.
</p>
<p class="leafygreen-ui-1kp3ins">
Transactions release all locks upon abort or commit.
</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">
When creating or dropping a collection immediately before
starting a transaction, if the collection is accessed within the
transaction, issue the create or drop operation 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>
to ensure that the transaction
can acquire the required locks.
</p>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Lock Request Timeout
<a class="headerlink leafygreen-ui-1kepx47" href="#lock-request-timeout" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-request-timeout">
</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 Atlas clusters restrict the use of 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. For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/unsupported-commands/#std-label-unsupported-commands" target="_self">
<span>
Unsupported Commands in Atlas
</span>
</a>
in
the Atlas documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
To modify your Atlas cluster parameters, contact
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/support/" target="_self">
<span>
Atlas Support
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
parameter to adjust how long transactions wait to acquire locks.
Increasing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
allows
operations in the transactions to wait the specified time to acquire
the required locks. This can help obviate transaction aborts on
momentary concurrent lock acquisitions, like fast-running metadata
operations. However, this could possibly delay the abort of deadlocked
transaction operations.
</p>
<p class="leafygreen-ui-1kp3ins">
You can also use operation-specific timeout by setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
-1
</code>
.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-txn-prod-considerations-ddl">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Pending DDL Operations and Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#pending-ddl-operations-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="pending-ddl-operations-and-transactions">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If a multi-document transaction is in progress, new DDL operations that
affect the same database(s) or collection(s) wait behind the
transaction. While these pending DDL operations exist, new transactions
that access the same database(s) or collection(s) as the pending DDL
operations cannot obtain the required locks and and will abort after
waiting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
. In
addition, new non-transaction operations that access the same
database(s) or collection(s) will block until they reach their
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
limit.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following scenarios:
</p>
<dl>
<dt>
DDL Operation That Requires a Collection Lock
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
While an in-progress transaction is performing various CRUD operations
on the
<code class="leafygreen-ui-1l06pbn">
employees
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database, an
administrator issues 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>
DDL
operation against the
<code class="leafygreen-ui-1l06pbn">
employees
</code>
collection.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
requires an exclusive
collection lock on the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
Until the in-progress transaction completes, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
operation must wait to obtain
the lock. Any new transaction that affects the
<code class="leafygreen-ui-1l06pbn">
employees
</code>
collection and starts while the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
is pending must wait until after
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
completes.
</p>
<p class="leafygreen-ui-1kp3ins">
The pending
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
DDL operation does
not affect transactions on other collections in the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database.
For example, a new transaction on the
<code class="leafygreen-ui-1l06pbn">
contractors
</code>
collection in
the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database can start and complete as normal.
</p>
</dd>
<dt>
DDL Operation That Requires a Database Lock
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
While an in-progress transaction is performing various CRUD operations
on the
<code class="leafygreen-ui-1l06pbn">
employees
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database, an
administrator issues the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/renameCollection/#mongodb-dbcommand-dbcmd.renameCollection">
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
</a>
DDL operation
to rename the
<code class="leafygreen-ui-1l06pbn">
vendors.contractors
</code>
collection to
<code class="leafygreen-ui-1l06pbn">
hr.contractors
</code>
.
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
requires a database lock on
the target database (
<code class="leafygreen-ui-1l06pbn">
hr
</code>
) when it differs from the source database
(
<code class="leafygreen-ui-1l06pbn">
vendors
</code>
).
</p>
<p class="leafygreen-ui-1kp3ins">
Until the in-progress transaction completes, the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
operation must wait to obtain the
lock. Any new transaction that affects the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database or
<em>
any
</em>
of its collections and starts while the
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
is
pending must wait until after
<code class="leafygreen-ui-1l06pbn">
renameCollection
</code>
completes.
</p>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
In either scenario, if the DDL operation remains pending for more than
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
, pending
transactions waiting behind that operation abort. That is, the value of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxTransactionLockRequestTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
maxTransactionLockRequestTimeoutMillis
</code>
</a>
must at least cover
the time required for the in-progress transaction
<em>
and
</em>
the pending DDL
operation to complete.
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-transactions-write-conflicts" target="_self">
<span>
In-progress Transactions and Write Conflicts
</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-transactions-stale-reads" target="_self">
<span>
In-progress Transactions and Stale Reads
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/faq/concurrency/#std-label-faq-concurrency-database-lock">
Which administrative commands lock a database?
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/faq/concurrency/#std-label-faq-concurrency-collection-lock">
Which administrative commands lock a collection?
</a>
</p>
</li>
</ul>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-transactions-write-conflicts">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
In-progress Transactions and Write Conflicts
<a class="headerlink leafygreen-ui-1kepx47" href="#in-progress-transactions-and-write-conflicts" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="in-progress-transactions-and-write-conflicts">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If a transaction is in progress and a write
outside the transaction modifies a document that an operation in the
transaction later tries to modify, the transaction aborts because of
a write conflict.
</p>
<p class="leafygreen-ui-1kp3ins">
If a transaction is in progress and has taken a lock
to modify a document, when a write outside the transaction tries to
modify the same document, the write waits until the transaction ends.
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-txns-locks" target="_self">
<span>
Acquiring Locks
</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-txn-prod-considerations-ddl" target="_self">
<span>
Pending DDL Operations and Transactions
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#mongodb-data--currentOp.prepareReadConflicts">
<code class="leafygreen-ui-1l06pbn">
$currentOp output
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-transactions-stale-reads">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
In-progress Transactions and Stale Reads
<a class="headerlink leafygreen-ui-1kepx47" href="#in-progress-transactions-and-stale-reads" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="in-progress-transactions-and-stale-reads">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Read operations inside a transaction can return old data, which is known as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-stale-read">
stale read
</a>
. Read operations inside a transaction are not guaranteed
to see writes performed by other committed transactions or
non-transactional writes. For example, consider the following sequence:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A transaction is in-progress.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A write outside the transaction deletes a document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A read operation inside the transaction can read the now-deleted document
since the operation uses a snapshot from before the write operation.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
To avoid stale reads inside transactions for a single document, you
can use the
<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>
method. 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>
example demonstrates how you can use
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndUpdate()
</code>
to take a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-write-lock">
write lock
</a>
and ensure
that your reads are up to date:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Insert a document into the employees collection"},{"@type":"HowToStep","text":"Start a session"},{"@type":"HowToStep","text":"Start a transaction"},{"@type":"HowToStep","text":"Note that inside the transaction, the findOneAndUpdate operation\nsets a new lockId field. You can set lockId field to any\nvalue, as long as it modifies the document. By updating the\ndocument, the transaction acquires a lock.If an operation outside of the transaction attempts to modify the\ndocument before you commit the transaction, MongoDB returns a write\nconflict error to the external operation.","name":"Use db.collection.findOneAndUpdate() inside the transaction"},{"@type":"HowToStep","text":"After you commit the transaction, MongoDB releases the lock.If any operation in the transaction fails, the transaction\naborts and all data changes made in the transaction are discarded\nwithout ever becoming visible in the collection.","name":"Commit the transaction"}],"name":"In-progress Transactions and Stale Reads","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">
Insert a document into the
<code class="leafygreen-ui-1l06pbn">
employees
</code>
collection
<a class="headerlink leafygreen-ui-1kepx47" href="#insert-a-document-into-the-employees-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="insert-a-document-into-the-employees-collection">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"hr\").employees.insertOne(\n { _id: 1, status: \"Active\" }\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">"hr"</span>).<span class="lg-highlight-property">employees</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</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">status</span>: <span class="lg-highlight-string">"Active"</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>
</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">
Start a session
<a class="headerlink leafygreen-ui-1kepx47" href="#start-a-session" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-a-session">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"session = db.getMongo().startSession( { readPreference: { mode: \"primary\" } } )","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">session <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">startSession</span>( <!-- -->{ <span class="lg-highlight-attr">readPreference</span>: <!-- -->{ <span class="lg-highlight-attr">mode</span>: <span class="lg-highlight-string">"primary"</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">
Start a transaction
<a class="headerlink leafygreen-ui-1kepx47" href="#start-a-transaction" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-a-transaction">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"session.startTransaction( { readConcern: { level: \"snapshot\" }, writeConcern: { w: \"majority\" } } )\n\nemployeesCollection = session.getDatabase(\"hr\").employees","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">session.<span class="lg-highlight-title lg-highlight-function">startTransaction</span>( <!-- -->{ <span class="lg-highlight-attr">readConcern</span>: <!-- -->{ <span class="lg-highlight-attr">level</span>: <span class="lg-highlight-string">"snapshot"</span> }<!-- -->, <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"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">employeesCollection <!-- -->= <!-- -->session.<span class="lg-highlight-title lg-highlight-function">getDatabase</span>(<span class="lg-highlight-string">"hr"</span>).<span class="lg-highlight-property">employees</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">
Use
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndUpdate()
</code>
inside the transaction
<a class="headerlink leafygreen-ui-1kepx47" href="#use-db.collection.findoneandupdate---inside-the-transaction" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-db.collection.findoneandupdate---inside-the-transaction">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"employeeDoc = employeesCollection.findOneAndUpdate(\n { _id: 1, status: \"Active\" },\n { $set: { lockId: ObjectId() } },\n { returnNewDocument: 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">employeeDoc <!-- -->= <!-- -->employeesCollection.<span class="lg-highlight-title lg-highlight-function">findOneAndUpdate</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">status</span>: <span class="lg-highlight-string">"Active"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">lockId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<!-- -->) } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">returnNewDocument</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">
Note that inside the transaction, the
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate
</code>
operation
sets a new
<code class="leafygreen-ui-1l06pbn">
lockId
</code>
field. You can set
<code class="leafygreen-ui-1l06pbn">
lockId
</code>
field to any
value, as long as it modifies the document. By updating the
document, the transaction acquires a lock.
</p>
<p class="leafygreen-ui-1kp3ins">
If an operation outside of the transaction attempts to modify the
document before you commit the transaction, MongoDB returns a write
conflict error to the external operation.
</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">
Commit the transaction
<a class="headerlink leafygreen-ui-1kepx47" href="#commit-the-transaction" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-the-transaction">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"session.commitTransaction()","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">session.<span class="lg-highlight-title lg-highlight-function">commitTransaction</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">
After you commit the transaction, MongoDB releases the lock.
</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 any operation in the transaction fails, the transaction
aborts and all data changes made in the transaction are discarded
without ever becoming visible in the collection.
</p>
</div>
</div>
</section>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
In-progress Transactions and Chunk Migration
<a class="headerlink leafygreen-ui-1kepx47" href="#in-progress-transactions-and-chunk-migration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="in-progress-transactions-and-chunk-migration">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-chunk-migration-procedure">
Chunk migration
</a>
acquires
exclusive collection locks during certain stages.
</p>
<p class="leafygreen-ui-1kp3ins">
If an ongoing transaction has a lock on a collection and a chunk
migration that involves that collection starts, these migration stages
must wait for the transaction to release the locks on the collection,
thereby impacting the performance of chunk migrations.
</p>
<p class="leafygreen-ui-1kp3ins">
If a chunk migration interleaves with a transaction (for instance, if a
transaction starts while a chunk migration is already in progress and
the migration completes before the transaction takes a lock on the
collection), the transaction errors during the commit and aborts.
</p>
<p class="leafygreen-ui-1kp3ins">
Depending on how the two operations interleave, some sample errors
include (the error messages have been abbreviated):
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
an error from cluster data placement change ... migration commit in progress for <namespace>
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Cannot find shardId the chunk belonged to at cluster time ...
</code>
</p>
</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/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDonorMoveChunkLockTimeout">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countDonorMoveChunkLockTimeout
</code>
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-transactions-prod-consideration-outside-reads">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Outside Reads During Commit
<a class="headerlink leafygreen-ui-1kepx47" href="#outside-reads-during-commit" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="outside-reads-during-commit">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
During the commit for a transaction, outside read operations may try
to read the same documents that will be modified by the transaction.
If the transaction writes to multiple shards, then during the commit
attempt across the shards:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Outside reads that use 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern-linearizable/#mongodb-readconcern-readconcern.-linearizable-">
<code class="leafygreen-ui-1l06pbn">
"linearizable"
</code>
</a>
wait until all writes of a transaction
are visible.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Outside reads that are part of causally consistent
sessions (those that include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-afterClusterTime">
afterClusterTime
</a>
) wait until all writes
of a transaction are visible.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Outside reads using other read concerns do not wait until all writes
of a transaction are visible, but instead read the
before-transaction version of the documents.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Information
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-information">
</div>
</a>
</h2>
<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-sharded-clusters/">
Production Considerations (Sharded Clusters)
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/configuration-options/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Self-Managed Configuration File Options
<a class="headerlink leafygreen-ui-1kepx47" href="#self-managed-configuration-file-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="self-managed-configuration-file-options">
</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="#configuration-file" target="_self">
<span>
Configuration File
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#file-format" target="_self">
<span>
File Format
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-the-configuration-file" target="_self">
<span>
Use the Configuration File
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#core-options" target="_self">
<span>
Core Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#systemlog-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
systemLog
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#processmanagement-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
processManagement
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#net-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
net
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#security-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
security
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#setparameter-option" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
setParameter
</code>
Option
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#storage-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
storage
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#operationprofiling-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
operationProfiling
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#replication-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
replication
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#sharding-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
sharding
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#auditlog-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
auditLog
</code>
Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#mongos-only-options" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
mongos
</code>
-only Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#windows-service-options" target="_self">
<span>
Windows Service Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#removed-mmapv1-options" target="_self">
<span>
Removed MMAPv1 Options
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The following page describes the configuration options available in
MongoDB 8.0. For configuration file options for other
versions of MongoDB, see the appropriate version of the MongoDB Manual.
</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 you're using MongoDB Atlas to manage your MongoDB deployments in the
cloud, you don't need to create a configuration file. To learn how
to configure settings for your MongoDB Atlas deployment, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/cluster-additional-settings/" target="_self">
<span>
Configure Additional Settings.
</span>
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In addition to using the configuration file options, the default
configuration for the MongoDB binaries also uses the operating system
environment variables.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-conf-file">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Configuration File
<a class="headerlink leafygreen-ui-1kepx47" href="#configuration-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="configuration-file">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can configure
<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 at
startup using a configuration file. The configuration file contains
settings that are equivalent 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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
command-line options. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-file-settings-command-line-options-mapping/#std-label-conf-file-command-line-mapping">
Self-Managed Configuration File Settings and Command-Line Options Mapping.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Using a configuration file makes managing
<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>
options easier, especially for large-scale
deployments. You can also add comments to the configuration file to
explain the server's settings.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
installed MongoDB
</a>
with a package manager
such as
<code class="leafygreen-ui-1l06pbn">
yum
</code>
or
<code class="leafygreen-ui-1l06pbn">
apt
</code>
on Linux or
<code class="leafygreen-ui-1l06pbn">
brew
</code>
on macOS, or with the
MSI installer on Windows, a default
<a aria-current="page" class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
has been provided as part of your
installation:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width: 10%;"/>
<col style="width: 25%;"/>
<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>
Platform
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Method
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Configuration File
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Linux
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
apt
</code>
,
<code class="leafygreen-ui-1l06pbn">
yum
</code>
, or
<code class="leafygreen-ui-1l06pbn">
zypper
</code>
Package Manager
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
/etc/mongod.conf
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
macOS
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
brew
</code>
Package Manager
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
/usr/local/etc/mongod.conf
</code>
(on Intel processors), or
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
/opt/homebrew/etc/mongod.conf
</code>
(on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://support.apple.com/en-us/HT211814" rel="noopener noreferrer">
<span>
Apple M1 processors)
</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>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Windows
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
MSI Installer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
<install directory>\bin\mongod.cfg
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
installed MongoDB
</a>
through a downloaded
<code class="leafygreen-ui-1l06pbn">
TGZ
</code>
or
<code class="leafygreen-ui-1l06pbn">
ZIP
</code>
file, you must create
your own configuration file. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/configuration/#std-label-base-config">
basic example
configuration
</a>
is a good place to start.
</p>
</li>
</ul>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
File Format
<a class="headerlink leafygreen-ui-1kepx47" href="#file-format" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="file-format">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB configuration files use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.yaml.org" rel="noopener noreferrer">
<span>
YAML
</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
<a class="footnote-reference header-buffer" href="#footnote-yaml-json" id="ref-yaml-json-id1">
[1]
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The following sample configuration file contains several
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
settings that you may adapt to your local configuration:
</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">
YAML does not support tab characters for indentation: use spaces instead.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"systemLog:\n destination: file\n path: \"/var/log/mongodb/mongod.log\"\n logAppend: true\nprocessManagement:\n fork: true\nnet:\n bindIp: 127.0.0.1\n port: 27017\nsetParameter:\n enableLocalhostAuthBypass: false\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">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><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logAppend:</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">net:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-number">127.0</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-attr">port:</span> <span class="lg-highlight-number">27017</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">enableLocalhostAuthBypass:</span> <span class="lg-highlight-literal">false</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">
The Linux package init scripts included in the official MongoDB packages depend
on specific values for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
, and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
or
<code class="leafygreen-ui-1l06pbn">
MONGODB_CONFIG_OVERRIDE_NOFORK
</code>
system environment variable. If you modify these settings in the default
configuration file,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
may not start.
</p>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-yaml-json" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-yaml-json-id1">
1
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
YAML is a superset of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-JSON">
JSON.
</a>
</td>
</tr>
</tbody>
</table>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Externally Sourced Values
<a class="headerlink leafygreen-ui-1kepx47" href="#externally-sourced-values" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="externally-sourced-values">
</div>
</a>
</h4>
<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 supports using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-expansion-directives">
expansion directives
</a>
in configuration
files to load externally sourced values. Expansion directives can
load values for specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-configuration-options" target="_self">
<span>
configuration file options
</span>
</a>
<em>
or
</em>
load the
entire configuration file.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following expansion directives are available:
</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>
Expansion Directive
</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/expansion-directives/#mongodb-configexpansion-configexpansion.__rest">
<code class="leafygreen-ui-1l06pbn">
__rest
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Allows users to specify a
<code class="leafygreen-ui-1l06pbn">
REST
</code>
endpoint as the external source
for configuration file options
<em>
or
</em>
the full configuration file.
</p>
<p class="leafygreen-ui-1kp3ins">
If the configuration file includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#mongodb-configexpansion-configexpansion.__rest">
<code class="leafygreen-ui-1l06pbn">
__rest
</code>
</a>
expansion, on Linux/macOS, the read access to the configuration file must be limited
to 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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
process only.
</p>
</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/expansion-directives/#mongodb-configexpansion-configexpansion.__exec">
<code class="leafygreen-ui-1l06pbn">
__exec
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Allows users to specify a shell or terminal command as the
external source for configuration file options
<em>
or
</em>
the
full configuration file.
</p>
<p class="leafygreen-ui-1kp3ins">
If the configuration file includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#mongodb-configexpansion-configexpansion.__exec">
<code class="leafygreen-ui-1l06pbn">
__exec
</code>
</a>
expansion, on Linux/macOS, the write access to the configuration file must be
limited to 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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
process only.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For complete documentation, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-externally-sourced-values">
Externally Sourced Configuration File Values for Self-Managed Deployments.
</a>
</p>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use the Configuration File
<a class="headerlink leafygreen-ui-1kepx47" href="#use-the-configuration-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-configuration-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>
using a config file,
specify the config file with the
<code class="leafygreen-ui-1l06pbn">
--config
</code>
option or the
<code class="leafygreen-ui-1l06pbn">
-f
</code>
option, as in the following examples:
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--config">
<code class="leafygreen-ui-1l06pbn">
mongod --config
<configuration file>
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-option-mongos.--config">
<code class="leafygreen-ui-1l06pbn">
mongos --config
<configuration file>
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config /etc/mongod.conf\n\nmongos --config /etc/mongos.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">mongod --config /etc/mongod.conf</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos --config /etc/mongos.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">
You can also use the
<code class="leafygreen-ui-1l06pbn">
-f
</code>
alias to specify the configuration
file, as in the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod -f /etc/mongod.conf\n\nmongos -f /etc/mongos.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">mongod -f /etc/mongod.conf</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos -f /etc/mongos.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">
If you installed from a package and have started MongoDB using your
system's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-init-script">
init script
</a>
, you are already using a configuration
file.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Expansion Directives and
<code class="leafygreen-ui-1l06pbn">
--configExpand
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#expansion-directives-and---configexpand" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="expansion-directives-and---configexpand">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
If you are using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-expansion-directives">
expansion directives
</a>
in the configuration file, you must include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand">
<code class="leafygreen-ui-1l06pbn">
--configExpand
</code>
</a>
option 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>
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 example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --config /etc/mongod.conf --configExpand \"rest,exec\"\nmongos --config /etc/mongos.conf --configExpand \"rest,exec\"","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 --config /etc/mongod.conf --configExpand <span class="lg-highlight-string">"rest,exec"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongos --config /etc/mongos.conf --configExpand <span class="lg-highlight-string">"rest,exec"</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 configuration file includes an expansion directive and you 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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
without specifying
that directive in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--configExpand">
<code class="leafygreen-ui-1l06pbn">
--configExpand
</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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
fails to start.
</p>
<p class="leafygreen-ui-1kp3ins">
For complete documentation, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/expansion-directives/#std-label-externally-sourced-values">
Externally Sourced Configuration File Values for Self-Managed Deployments.
</a>
</p>
</section>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Core Options
<a class="headerlink leafygreen-ui-1kepx47" href="#core-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="core-options">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-systemlog-options">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
systemLog
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#systemlog-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="systemlog-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"systemLog:\n verbosity: <int>\n quiet: <boolean>\n traceAllExceptions: <boolean>\n syslogFacility: <string>\n path: <string>\n logAppend: <boolean>\n logRotate: <string>\n destination: <string>\n timeStampFormat: <string>\n component:\n accessControl:\n verbosity: <int>\n command:\n verbosity: <int>\n\n # COMMENT additional component verbosity settings omitted for brevity","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">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quiet:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">traceAllExceptions:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">syslogFacility:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logAppend:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logRotate:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeStampFormat:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">component:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accessControl:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></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"> COMMENT additional component </span><span class="lg-highlight-comment">verbosity</span><span class="lg-highlight-comment"> settings omitted for </span><span class="lg-highlight-comment">brevity</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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.verbosity" 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-setting-systemLog.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
log message
</a>
verbosity level for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-components">
components
</a>
. The
verbosity level determines the amount of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational and
Debug
</a>
messages MongoDB outputs.
<a class="footnote-reference header-buffer" href="#footnote-log-message" id="ref-log-message-id2">
[2]
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To use a different verbosity level for a named component, use the
component's verbosity setting. For example, use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.accessControl.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.accessControl.verbosity
</code>
</span>
</a>
to set the
verbosity level specifically for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-ACCESS">
<code class="leafygreen-ui-1l06pbn">
ACCESS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<code class="leafygreen-ui-1l06pbn">
systemLog.component.<name>.verbosity
</code>
settings for
specific component verbosity settings.
</p>
<p class="leafygreen-ui-1kp3ins">
For various ways to set the log verbosity level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-configure-verbosity">
Configure Log Verbosity Levels.
</a>
</p>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-log-message" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-log-message-id2">
2
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
Starting in version 4.2, MongoDB includes the Debug verbosity level
(1-5) in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
log messages
</a>
. For example,
if the verbosity level is 2, MongoDB logs
<code class="leafygreen-ui-1l06pbn">
D2
</code>
. In previous
versions, MongoDB log messages only specified
<code class="leafygreen-ui-1l06pbn">
D
</code>
for Debug level.
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.quiet
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.quiet" 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-setting-systemLog.quiet">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
in a quiet mode
that attempts to limit the amount of output.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.quiet" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.quiet
</code>
</span>
</a>
is
<strong>
not
</strong>
recommended for production
systems as it may make tracking problems during particular
connections much more difficult.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.traceAllExceptions
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.traceAllExceptions" 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-setting-systemLog.traceAllExceptions">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Print verbose information for debugging. Use for additional logging
for support-related troubleshooting.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.syslogFacility
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.syslogFacility" 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-setting-systemLog.syslogFacility">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: user
</p>
<p class="leafygreen-ui-1kp3ins">
The facility level used when logging messages to syslog.
The value you specify must be supported by your
operating system's implementation of syslog. To use this option, you
must set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.destination
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
syslog
</code>
.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.path" 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-setting-systemLog.path">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The path of the log file to which
<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>
should send all diagnostic
logging information, rather than the standard output or the host's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-syslog">
syslog
</a>
. MongoDB creates the log file at the specified path.
</p>
<p class="leafygreen-ui-1kp3ins">
The Linux package init scripts do not expect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
</span>
</a>
to change from the
defaults. If you use the Linux packages and change
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
</span>
</a>
, you must
use your own init scripts and disable the built-in scripts.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.logAppend
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.logAppend" 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-setting-systemLog.logAppend">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
appends new entries to the end of the existing log file when
the instance restarts. Without this option,
<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>
backs up the
existing log and create a new file.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.logRotate
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.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-setting-systemLog.logRotate">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: rename
</p>
<p class="leafygreen-ui-1kp3ins">
Determines the behavior for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/logRotate/#mongodb-dbcommand-dbcmd.logRotate">
<code class="leafygreen-ui-1l06pbn">
logRotate
</code>
</a>
command when
rotating the server log and/or the audit log. Specify either
<code class="leafygreen-ui-1l06pbn">
rename
</code>
or
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
rename
</code>
renames the log file.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
closes and reopens the log file following the typical
Linux/Unix log rotate behavior. Use
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
when using the
Linux/Unix logrotate utility to avoid log loss.
</p>
<p class="leafygreen-ui-1kp3ins">
If you specify
<code class="leafygreen-ui-1l06pbn">
reopen
</code>
, you must also set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.logAppend" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.logAppend
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.destination
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.destination" 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-setting-systemLog.destination">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The destination to which MongoDB sends all log output. Specify either
<code class="leafygreen-ui-1l06pbn">
file
</code>
or
<code class="leafygreen-ui-1l06pbn">
syslog
</code>
. If you specify
<code class="leafygreen-ui-1l06pbn">
file
</code>
, you must also specify
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.path
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not specify
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.destination
</code>
</span>
</a>
, MongoDB sends
all log output to standard output.
</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">
The
<code class="leafygreen-ui-1l06pbn">
syslog
</code>
daemon generates timestamps when it logs a message, not
when MongoDB issues the message. This can lead to misleading timestamps
for log entries, especially when the system is under heavy load. We
recommend using the
<code class="leafygreen-ui-1l06pbn">
file
</code>
option for production systems to ensure
accurate timestamps.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.timeStampFormat
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.timeStampFormat" 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-setting-systemLog.timeStampFormat">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: iso8601-local
</p>
<p class="leafygreen-ui-1kp3ins">
The time format for timestamps in log messages. Specify one of the
following values:
</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>
Value
</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">
iso8601-utc
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Displays timestamps in Coordinated Universal Time (UTC) in the
ISO-8601 format. For example, for New York at the start of the
Epoch:
<code class="leafygreen-ui-1l06pbn">
1970-01-01T00:00:00.000Z
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
iso8601-local
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Displays timestamps in local time in the ISO-8601
format. For example, for New York at the start of the Epoch:
<code class="leafygreen-ui-1l06pbn">
1969-12-31T19:00:00.000-05:00
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.timeStampFormat" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.timeStampFormat
</code>
</span>
</a>
no longer supports
<code class="leafygreen-ui-1l06pbn">
ctime
</code>
. An example of
<code class="leafygreen-ui-1l06pbn">
ctime
</code>
formatted date is:
<code class="leafygreen-ui-1l06pbn">
Wed Dec 31 18:17:54.811
</code>
.
</p>
</div>
</div>
</dd>
</dl>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
systemLog.component
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#systemlog.component-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="systemlog.component-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"systemLog:\n component:\n accessControl:\n verbosity: <int>\n command:\n verbosity: <int>\n\n # COMMENT some component verbosity settings omitted for brevity\n\n replication:\n verbosity: <int>\n election:\n verbosity: <int>\n heartbeats:\n verbosity: <int>\n initialSync:\n verbosity: <int>\n rollback:\n verbosity: <int>\n storage:\n verbosity: <int>\n journal:\n verbosity: <int>\n recovery:\n verbosity: <int>\n write:\n verbosity: <int>","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">systemLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">component:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accessControl:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></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"> COMMENT some component </span><span class="lg-highlight-comment">verbosity</span><span class="lg-highlight-comment"> settings omitted for </span><span class="lg-highlight-comment">brevity</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-attr">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">election:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">heartbeats:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">initialSync:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">rollback:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></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">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">journal:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">recovery:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">write:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">verbosity:</span> <span class="lg-highlight-string"><int></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">
Starting in version 4.2, MongoDB includes the Debug verbosity level
(1-5) in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
log messages
</a>
. For example,
if the verbosity level is 2, MongoDB logs
<code class="leafygreen-ui-1l06pbn">
D2
</code>
. In previous
versions, MongoDB log messages only specified
<code class="leafygreen-ui-1l06pbn">
D
</code>
for Debug level.
</p>
</div>
</div>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.accessControl.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.accessControl.verbosity" 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-setting-systemLog.component.accessControl.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
access control. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-ACCESS">
<code class="leafygreen-ui-1l06pbn">
ACCESS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.command.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.command.verbosity" 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-setting-systemLog.component.command.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
commands. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-COMMAND">
<code class="leafygreen-ui-1l06pbn">
COMMAND
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.control.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.control.verbosity" 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-setting-systemLog.component.control.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
control operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-CONTROL">
<code class="leafygreen-ui-1l06pbn">
CONTROL
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.ftdc.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.ftdc.verbosity" 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-setting-systemLog.component.ftdc.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
diagnostic data collection operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-FTDC">
<code class="leafygreen-ui-1l06pbn">
FTDC
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.geo.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.geo.verbosity" 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-setting-systemLog.component.geo.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
geospatial parsing operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-GEO">
<code class="leafygreen-ui-1l06pbn">
GEO
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.index.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.index.verbosity" 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-setting-systemLog.component.index.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
indexing operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-INDEX">
<code class="leafygreen-ui-1l06pbn">
INDEX
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.network.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.network.verbosity" 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-setting-systemLog.component.network.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
networking operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-NETWORK">
<code class="leafygreen-ui-1l06pbn">
NETWORK
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.query.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.query.verbosity" 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-setting-systemLog.component.query.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
query operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-QUERY">
<code class="leafygreen-ui-1l06pbn">
QUERY
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.queryStats.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.queryStats.verbosity" 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-setting-systemLog.component.queryStats.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to invocations of
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-QUERYSTATS">
<code class="leafygreen-ui-1l06pbn">
QUERYSTATS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the default log verbosity level, and only includes
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
informational
</a>
messages. No
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
calls are logged at this level.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
2
</code>
increases the verbosity level to include
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
calls where
<code class="leafygreen-ui-1l06pbn">
algorithm
</code>
is
<code class="leafygreen-ui-1l06pbn">
"hmac-sha-256"
</code>
. Any HMAC keys are
redacted.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
3
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
calls where
<code class="leafygreen-ui-1l06pbn">
algorithm
</code>
is
<code class="leafygreen-ui-1l06pbn">
"hmac-sha-256"
</code>
, and the corresponding results. Each result is its own
entry and there is a final entry with the string
<code class="leafygreen-ui-1l06pbn">
"we finished"
</code>
.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.replication.verbosity" 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-setting-systemLog.component.replication.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
replication. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-REPL">
<code class="leafygreen-ui-1l06pbn">
REPL
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.election.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.replication.election.verbosity" 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-setting-systemLog.component.replication.election.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
election. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-ELECTION">
<code class="leafygreen-ui-1l06pbn">
ELECTION
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.election.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.election.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.verbosity
</code>
</span>
</a>
level also applies to
election components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.heartbeats.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.replication.heartbeats.verbosity" 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-setting-systemLog.component.replication.heartbeats.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
heartbeats. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-REPL_HB">
<code class="leafygreen-ui-1l06pbn">
REPL_HB
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.heartbeats.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.heartbeats.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.verbosity
</code>
</span>
</a>
level also applies to
heartbeats components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.initialSync.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.replication.initialSync.verbosity" 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-setting-systemLog.component.replication.initialSync.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
initialSync. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-INITSYNC">
<code class="leafygreen-ui-1l06pbn">
INITSYNC
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.initialSync.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.initialSync.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.verbosity
</code>
</span>
</a>
level also applies to
initialSync components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.rollback.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.replication.rollback.verbosity" 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-setting-systemLog.component.replication.rollback.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
rollback. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-ROLLBACK">
<code class="leafygreen-ui-1l06pbn">
ROLLBACK
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.rollback.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.rollback.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.replication.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.replication.verbosity
</code>
</span>
</a>
level also applies to
rollback components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.sharding.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.sharding.verbosity" 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-setting-systemLog.component.sharding.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
sharding. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-SHARDING">
<code class="leafygreen-ui-1l06pbn">
SHARDING
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.verbosity" 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-setting-systemLog.component.storage.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
storage. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-STORAGE">
<code class="leafygreen-ui-1l06pbn">
STORAGE
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.journal.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.journal.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.verbosity
</code>
</span>
</a>
level also applies to
journaling components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.journal.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.journal.verbosity" 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-setting-systemLog.component.storage.journal.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
journaling. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-JOURNAL">
<code class="leafygreen-ui-1l06pbn">
JOURNAL
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.journal.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.journal.verbosity
</code>
</span>
</a>
is
unset, the journaling components have the same verbosity level as the
parent storage components: i.e. either the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.verbosity
</code>
</span>
</a>
level if
set or the default verbosity level.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.recovery.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.recovery.verbosity" 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-setting-systemLog.component.storage.recovery.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
recovery. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-RECOVERY">
<code class="leafygreen-ui-1l06pbn">
RECOVERY
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.recovery.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.recovery.verbosity
</code>
</span>
</a>
is unset,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-systemLog.component.storage.verbosity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.verbosity
</code>
</span>
</a>
level also applies to
recovery components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.verbosity" 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-setting-systemLog.component.storage.wt.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WT">
<code class="leafygreen-ui-1l06pbn">
WT
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtBackup.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtBackup.verbosity" 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-setting-systemLog.component.storage.wt.wtBackup.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to backup operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTBACKUP">
<code class="leafygreen-ui-1l06pbn">
WTBACKUP
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtCheckpoint.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtCheckpoint.verbosity" 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-setting-systemLog.component.storage.wt.wtCheckpoint.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to checkpoint operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTCHKPT">
<code class="leafygreen-ui-1l06pbn">
WTCHKPT
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtCompact.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtCompact.verbosity" 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-setting-systemLog.component.storage.wt.wtCompact.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to compaction operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTCMPCT">
<code class="leafygreen-ui-1l06pbn">
WTCMPCT
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtEviction.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtEviction.verbosity" 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-setting-systemLog.component.storage.wt.wtEviction.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to eviction operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTEVICT">
<code class="leafygreen-ui-1l06pbn">
WTEVICT
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtHS.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtHS.verbosity" 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-setting-systemLog.component.storage.wt.wtHS.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to history store operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTHS">
<code class="leafygreen-ui-1l06pbn">
WTHS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtRecovery.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtRecovery.verbosity" 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-setting-systemLog.component.storage.wt.wtRecovery.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to recovery operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTRECOV">
<code class="leafygreen-ui-1l06pbn">
WTRECOV
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtRTS.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtRTS.verbosity" 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-setting-systemLog.component.storage.wt.wtRTS.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to rollback to stable
(RTS) operations performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTRTS">
<code class="leafygreen-ui-1l06pbn">
WTRTS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtSalvage.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtSalvage.verbosity" 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-setting-systemLog.component.storage.wt.wtSalvage.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to salvage operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTSLVG">
<code class="leafygreen-ui-1l06pbn">
WTSLVG
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtTimestamp.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtTimestamp.verbosity" 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-setting-systemLog.component.storage.wt.wtTimestamp.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to timestamps
used by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTTS">
<code class="leafygreen-ui-1l06pbn">
WTTS
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtTransaction.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtTransaction.verbosity" 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-setting-systemLog.component.storage.wt.wtTransaction.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to transaction operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTTXN">
<code class="leafygreen-ui-1l06pbn">
WTTXN
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtVerify.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtVerify.verbosity" 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-setting-systemLog.component.storage.wt.wtVerify.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to verification operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTVRFY">
<code class="leafygreen-ui-1l06pbn">
WTVRFY
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.storage.wt.wtWriteLog.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.storage.wt.wtWriteLog.verbosity" 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-setting-systemLog.component.storage.wt.wtWriteLog.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity for components related to log write operations
performed by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
storage engine.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WTWRTLOG">
<code class="leafygreen-ui-1l06pbn">
WTWRTLOG
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.transaction.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.transaction.verbosity" 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-setting-systemLog.component.transaction.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
transaction. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-TXN">
<code class="leafygreen-ui-1l06pbn">
TXN
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
systemLog.component.write.verbosity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-systemLog.component.write.verbosity" 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-setting-systemLog.component.write.verbosity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The log message verbosity level for components related to
write operations. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#mongodb-data-WRITE">
<code class="leafygreen-ui-1l06pbn">
WRITE
</code>
</a>
components.
</p>
<p class="leafygreen-ui-1kp3ins">
The verbosity level can range from
<code class="leafygreen-ui-1l06pbn">
0
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
0
</code>
is the MongoDB's default log verbosity level, to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Informational
</a>
messages.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
5
</code>
increases the verbosity level to include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-severity-levels">
Debug
</a>
messages.
</p>
</li>
</ul>
</dd>
</dl>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
processManagement
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#processmanagement-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="processmanagement-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"processManagement:\n fork: <boolean>\n pidFilePath: <string>\n timeZoneInfo: <string>","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">processManagement:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fork:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pidFilePath:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeZoneInfo:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.fork" 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-setting-processManagement.fork">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Enable a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-daemon">
daemon
</a>
mode that runs the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
process in the background. By default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
does not run as a daemon.
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
as a daemon, set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
or use a controlling process that
handles the daemonization process (for example,
<code class="leafygreen-ui-1l06pbn">
systemd
</code>
).
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
option is not supported on Windows.
</p>
<p class="leafygreen-ui-1kp3ins">
The Linux package init scripts do not expect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
to change from the
defaults. If you use the Linux packages and change
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
, you must
use your own init scripts and disable the built-in scripts.
</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">
Alternatively, you can set the
<code class="leafygreen-ui-1l06pbn">
MONGODB_CONFIG_OVERRIDE_NOFORK
</code>
environment variable on your system to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
process in the
background. If you set the environment variable, it overrides the
setting for
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.pidFilePath
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.pidFilePath" 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-setting-processManagement.pidFilePath">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a file location to store the process ID (PID) 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process. The user running the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
or
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
process must be able to write to this path. If the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.pidFilePath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.pidFilePath
</code>
</span>
</a>
option is not
specified, the process does not create a PID file. This option is generally
only useful in combination with the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.fork" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.fork
</code>
</span>
</a>
setting.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Linux
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
On Linux, PID file management is generally the responsibility of
your distro's init system: usually a service file in the
<code class="leafygreen-ui-1l06pbn">
/etc/init.d
</code>
directory, or a systemd unit file registered with
<code class="leafygreen-ui-1l06pbn">
systemctl
</code>
. Only
use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.pidFilePath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.pidFilePath
</code>
</span>
</a>
option if you are not using one of these init
systems. For more information, please see the respective
<a class="leafygreen-ui-tqgtui" href="/docs/manual/installation/#std-label-tutorial-installation">
Installation Guide
</a>
for your operating system.
</p>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
macOS
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
On macOS, PID file management is generally handled by
<code class="leafygreen-ui-1l06pbn">
brew
</code>
. Only use
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.pidFilePath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.pidFilePath
</code>
</span>
</a>
option if you are not using
<code class="leafygreen-ui-1l06pbn">
brew
</code>
on your macOS system.
For more information, please see the respective
Installation Guide for your operating system.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.timeZoneInfo
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.timeZoneInfo" 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-setting-processManagement.timeZoneInfo">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The full path from which to load the time zone database. If this option
is not provided, then MongoDB uses its built-in time zone database.
</p>
<p class="leafygreen-ui-1kp3ins">
The configuration file included with Linux and macOS packages sets the
time zone database path to
<code class="leafygreen-ui-1l06pbn">
/usr/share/zoneinfo
</code>
by default.
</p>
<p class="leafygreen-ui-1kp3ins">
The built-in time zone database is a copy of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.iana.org/time-zones" rel="noopener noreferrer">
<span>
Olson/IANA time zone
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>
. It is updated along with
MongoDB releases, but the time zone database release cycle
differs from the MongoDB release cycle. The most recent release of
the time zone database is available on our
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip" rel="noopener noreferrer">
<span>
download site
</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 class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
MongoDB uses the third party
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/derickr/timelib" rel="noopener noreferrer">
<span>
timelib
</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>
library to provide accurate
conversions between timezones. Due to a recent update,
<code class="leafygreen-ui-1l06pbn">
timelib
</code>
could create inaccurate time zone conversions in older versions of
MongoDB.
</p>
<p class="leafygreen-ui-1kp3ins">
To explicitly link to the time zone database in versions of MongoDB
prior to 5.0, download the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://downloads.mongodb.org/olson_tz_db/timezonedb-latest.zip" rel="noopener noreferrer">
<span>
time zone 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>
.
and use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--timeZoneInfo">
<code class="leafygreen-ui-1l06pbn">
timeZoneInfo
</code>
</a>
parameter.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
net
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#net-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="net-options">
</div>
</a>
</h3>
<div>
<p>
<em>
Changed in version 5.0
</em>
: MongoDB removes the
<code class="leafygreen-ui-1l06pbn">
net.serviceExecutor
</code>
configuration option and the
corresponding
<code class="leafygreen-ui-1l06pbn">
--serviceExecutor
</code>
command-line option.
</p>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n port: <int>\n bindIp: <string>\n bindIpAll: <boolean>\n maxIncomingConnections: <int>\n wireObjectCheck: <boolean>\n ipv6: <boolean>\n unixDomainSocket:\n enabled: <boolean>\n pathPrefix: <string>\n filePermissions: <int>\n tls:\n certificateSelector: <string>\n clusterCertificateSelector: <string>\n mode: <string>\n certificateKeyFile: <string>\n certificateKeyFilePassword: <string>\n clusterFile: <string>\n clusterPassword: <string>\n CAFile: <string>\n clusterCAFile: <string>\n clusterAuthX509:\n attributes: <string>\n extensionValue: <string>\n CRLFile: <string>\n allowConnectionsWithoutCertificates: <boolean>\n allowInvalidCertificates: <boolean>\n allowInvalidHostnames: <boolean>\n disabledProtocols: <string>\n FIPSMode: <boolean>\n logVersions: <string>\n compression:\n compressors: <string>","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">port:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIp:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bindIpAll:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxIncomingConnections:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wireObjectCheck:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ipv6:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unixDomainSocket:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">enabled:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pathPrefix:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filePermissions:</span> <span class="lg-highlight-string"><int></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">certificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterCertificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFilePassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterPassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterCAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthX509:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">attributes:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extensionValue:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CRLFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowConnectionsWithoutCertificates:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowInvalidCertificates:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowInvalidHostnames:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">disabledProtocols:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">FIPSMode:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logVersions:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">compression:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">compressors:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.port" 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-setting-net.port">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
27017 for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
(if not a shard member or a config server
member) or
<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">
27018 if
<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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-sharding.clusterRole" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
shard member
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
27019 if
<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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-sharding.clusterRole" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
config server member
</code>
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The TCP port on which the MongoDB instance listens for
client connections.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
net.port
</code>
option accepts a range of values between
<code class="leafygreen-ui-1l06pbn">
0
</code>
and
<code class="leafygreen-ui-1l06pbn">
65535
</code>
.
Setting the port to
<code class="leafygreen-ui-1l06pbn">
0
</code>
configures
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to use an arbitrary port
assigned by the operating system.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.bindIp" 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-setting-net.bindIp">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: localhost
</p>
<p class="leafygreen-ui-1kp3ins">
The hostnames and/or IP addresses and/or full Unix domain socket
paths on which
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
should
listen for client connections. You may attach
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to any interface. To bind to multiple
addresses, enter a list of comma-separated values.
</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">
<code class="leafygreen-ui-1l06pbn">
localhost,/tmp/mongod.sock
</code>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can specify both IPv4 and IPv6 addresses, or hostnames that
resolve to an IPv4 or IPv6 address.
</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">
<code class="leafygreen-ui-1l06pbn">
localhost, 2001:0DB8:e132:ba26:0d5c:2774:e7f9:d513
</code>
</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">
If specifying an IPv6 address
<em>
or
</em>
a hostname that resolves to an
IPv6 address to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
, you must start
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.ipv6" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.ipv6 : true
</code>
</span>
</a>
to enable IPv6 support.
Specifying an IPv6 address to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
does not
enable IPv6 support.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If specifying a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Link-local_address#IPv6" rel="noopener noreferrer">
<span>
link-local IPv6 address
</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>
(
<code class="leafygreen-ui-1l06pbn">
fe80::/10
</code>
), you must append the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/IPv6_address#Scoped_literal_IPv6_addresses_(with_zone_index)" rel="noopener noreferrer">
<span>
zone index
</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 that address (i.e.
<code class="leafygreen-ui-1l06pbn">
fe80::<address>%<adapter-name>
</code>
).
</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">
<code class="leafygreen-ui-1l06pbn">
localhost,fe80::a00:27ff:fee0:1fcf%enp0s3
</code>
</p>
</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">
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>
<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 you bind your instance to a publicly-accessible IP address,
you must secure your cluster from unauthorized access. For a complete
list of security recommendations, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist">
Security Checklist for Self-Managed Deployments
</a>
. At minimum, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth">
enabling authentication
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening">
hardening
network infrastructure.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information about IP Binding, refer to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/">
IP Binding in Self-Managed Deployments
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
To bind to all IPv4 addresses, enter
<code class="leafygreen-ui-1l06pbn">
0.0.0.0
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To bind to all IPv4 and IPv6 addresses, enter
<code class="leafygreen-ui-1l06pbn">
::,0.0.0.0
</code>
or
an asterisk
<code class="leafygreen-ui-1l06pbn">
"*"
</code>
(enclose the asterisk in quotes to distinguish from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://yaml.org/spec/1.2/spec.html#alias/" rel="noopener noreferrer">
<span>
YAML alias nodes
</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>
).
Alternatively, use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
setting.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
are mutually
exclusive. That is, you can specify one or the other, but not
both.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The command-line option
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
overrides the configuration
file setting
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
.
</span>
</a>
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To configure cluster nodes for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Split-horizon_DNS" rel="noopener noreferrer">
<span>
split horizon DNS
</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>
, use host names
instead of IP addresses.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB v5.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetInitiate/#mongodb-dbcommand-dbcmd.replSetInitiate">
<code class="leafygreen-ui-1l06pbn">
replSetInitiate
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetReconfig/#mongodb-dbcommand-dbcmd.replSetReconfig">
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</a>
reject configurations that use IP
addresses instead of hostnames.
</p>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.disableSplitHorizonIPCheck">
<code class="leafygreen-ui-1l06pbn">
disableSplitHorizonIPCheck
</code>
</a>
to modify nodes that
cannot be updated to use host names. The parameter only applies to the
configuration commands.
</p>
<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>
do not rely on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.disableSplitHorizonIPCheck">
<code class="leafygreen-ui-1l06pbn">
disableSplitHorizonIPCheck
</code>
</a>
for validation at startup.
Legacy
<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 that use IP
addresses instead of host names can start after an upgrade.
</p>
<p class="leafygreen-ui-1kp3ins">
Instances that are configured with IP addresses log a warning to use
host names instead of IP addresses.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.bindIpAll" 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-setting-net.bindIpAll">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
If true, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
instance binds to all IPv4
addresses (i.e.
<code class="leafygreen-ui-1l06pbn">
0.0.0.0
</code>
). If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
starts with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.ipv6" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.ipv6 : true
</code>
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
also binds to all IPv6 addresses
(i.e.
<code class="leafygreen-ui-1l06pbn">
::
</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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
only supports IPv6 if started with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.ipv6" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.ipv6 : true
</code>
</span>
</a>
. Specifying
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
alone does not enable IPv6 support.
</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">
Before you bind your instance to a publicly-accessible IP address,
you must secure your cluster from unauthorized access. For a complete
list of security recommendations, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist">
Security Checklist for Self-Managed Deployments
</a>
. At minimum, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth">
enabling authentication
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening">
hardening
network infrastructure.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information about IP Binding, refer to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/">
IP Binding in Self-Managed Deployments
</a>
documentation.
</p>
<p class="leafygreen-ui-1kp3ins">
Alternatively, set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
::,0.0.0.0
</code>
or to an asterisk
<code class="leafygreen-ui-1l06pbn">
"*"
</code>
(enclose the asterisk in quotes to distinguish from
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://yaml.org/spec/1.2/spec.html#alias/" rel="noopener noreferrer">
<span>
YAML alias nodes
</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 bind to all IP
addresses.
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
are mutually
exclusive. Specifying both options causes
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to throw
an error and terminate.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.maxIncomingConnections
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.maxIncomingConnections" 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-setting-net.maxIncomingConnections">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<div class="line-block">
<div class="line">
<em>
Default (Windows):
</em>
1,000,000
</div>
<div class="line">
<em>
Default (Linux):
</em>
(
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://man7.org/linux/man-pages/man2/getrlimit.2.html" rel="noopener noreferrer">
<span>
RLIMIT_NOFILE
</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>
) * 0.8
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The maximum number of simultaneous connections that
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
accepts. This setting has no effect if it is higher than your operating
system's configured maximum connection tracking threshold.
</p>
<p class="leafygreen-ui-1kp3ins">
Do not assign too low of a value to this option, or you may
encounter errors during normal application operation.
</p>
<p class="leafygreen-ui-1kp3ins">
This is particularly useful for a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
if you have a client
that creates multiple connections and allows them to timeout rather
than closing them.
</p>
<p class="leafygreen-ui-1kp3ins">
In this case, set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.maxIncomingConnections" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
maxIncomingConnections
</code>
</span>
</a>
to a value slightly
higher than the maximum number of connections that the client creates, or the
maximum size of the connection pool.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting prevents the
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
from causing connection spikes on
the individual
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shards
</a>
. Spikes like these may disrupt the
operation and memory allocation of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.wireObjectCheck
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.wireObjectCheck" 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-setting-net.wireObjectCheck">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
true
</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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance validates
all requests from clients upon receipt to prevent clients from inserting
malformed or invalid BSON into a MongoDB database.
</p>
<p class="leafygreen-ui-1kp3ins">
For objects with a high degree of sub-document nesting,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.wireObjectCheck" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.wireObjectCheck
</code>
</span>
</a>
can
have a small impact on performance.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.ipv6
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.ipv6" 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-setting-net.ipv6">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.ipv6" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.ipv6
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to enable IPv6 support.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
disables IPv6 support by default.
</p>
<p class="leafygreen-ui-1kp3ins">
Setting
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.ipv6" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.ipv6
</code>
</span>
</a>
does
<em>
not
</em>
direct the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to listen on any
local IPv6 addresses or interfaces. To configure the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to
listen on an IPv6 interface, you must either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Configure
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
with one or more IPv6 addresses or
hostnames that resolve to IPv6 addresses,
<strong>
or
</strong>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIpAll" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIpAll
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
</ul>
</dd>
</dl>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#net.unixdomainsocket-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="net.unixdomainsocket-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n unixDomainSocket:\n enabled: <boolean>\n pathPrefix: <string>\n filePermissions: <int>","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">unixDomainSocket:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">enabled:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pathPrefix:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filePermissions:</span> <span class="lg-highlight-string"><int></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.enabled
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.unixDomainSocket.enabled" 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-setting-net.unixDomainSocket.enabled">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
Enable or disable listening on the UNIX domain socket.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.unixDomainSocket.enabled" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.enabled
</code>
</span>
</a>
applies only
to Unix-based systems.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.unixDomainSocket.enabled" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.enabled
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
listens on the UNIX socket.
</p>
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process always listens on the UNIX socket unless
one of the following is true:
</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="#mongodb-setting-net.unixDomainSocket.enabled" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.enabled
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
--nounixsocket
</code>
is set. The command
line option takes precedence over the configuration file setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
is not set
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
does not specify
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
or its associated IP address
</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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.pathPrefix
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.unixDomainSocket.pathPrefix" 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-setting-net.unixDomainSocket.pathPrefix">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: /tmp
</p>
<p class="leafygreen-ui-1kp3ins">
The path for the UNIX socket.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.unixDomainSocket.pathPrefix" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.pathPrefix
</code>
</span>
</a>
applies only
to Unix-based systems.
</p>
<p class="leafygreen-ui-1kp3ins">
If this option has no value, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
process creates a socket with
<code class="leafygreen-ui-1l06pbn">
/tmp
</code>
as a prefix. MongoDB
creates and listens on a UNIX socket unless one of the following is true:
</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="#mongodb-setting-net.unixDomainSocket.enabled" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.enabled
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
--nounixsocket
</code>
is set
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
is not set
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.bindIp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.bindIp
</code>
</span>
</a>
does not specify
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
or its associated IP address
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.filePermissions
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.unixDomainSocket.filePermissions" 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-setting-net.unixDomainSocket.filePermissions">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
0700
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Sets the permission for the UNIX domain socket file.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.unixDomainSocket.filePermissions" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.unixDomainSocket.filePermissions
</code>
</span>
</a>
applies only to Unix-based systems.
</p>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-net-tls-conf-options">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
net.tls
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#net.tls-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="net.tls-options">
</div>
</a>
</h4>
<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
<code class="leafygreen-ui-1l06pbn">
tls
</code>
options provide identical functionality as the
previous
<code class="leafygreen-ui-1l06pbn">
ssl
</code>
options.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n tls:\n mode: <string>\n certificateKeyFile: <string>\n certificateKeyFilePassword: <string>\n certificateSelector: <string>\n clusterCertificateSelector: <string>\n clusterFile: <string>\n clusterPassword: <string>\n clusterAuthX509:\n attributes: <string>\n extensionValue: <string>\n CAFile: <string>\n clusterCAFile: <string>\n CRLFile: <string>\n allowConnectionsWithoutCertificates: <boolean>\n allowInvalidCertificates: <boolean>\n allowInvalidHostnames: <boolean>\n disabledProtocols: <string>\n FIPSMode: <boolean>\n logVersions: <string>","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">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateKeyFilePassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">certificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterCertificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterPassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthX509:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">attributes:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extensionValue:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterCAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">CRLFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowConnectionsWithoutCertificates:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowInvalidCertificates:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">allowInvalidHostnames:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">disabledProtocols:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">FIPSMode:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logVersions:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.mode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.mode" 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-setting-net.tls.mode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Enables TLS used for all network connections. The
argument to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.mode" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.mode
</code>
</span>
</a>
setting can be one of the following:
</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>
Value
</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">
disabled
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The server does not use TLS.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
allowTLS
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Connections between servers do not use TLS. For incoming
connections, the server accepts both TLS and non-TLS.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
preferTLS
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Connections between servers use TLS. For incoming
connections, the server accepts both TLS and non-TLS.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
requireTLS
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The server uses and accepts only TLS encrypted connections.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.CAFile
</code>
is not
specified and you are not using x.509 authentication, you must set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsUseSystemCA">
<code class="leafygreen-ui-1l06pbn">
tlsUseSystemCA
</code>
</a>
parameter to
<code class="leafygreen-ui-1l06pbn">
true
</code>
. This makes MongoDB use
the system-wide CA certificate store when connecting to a TLS-enabled server.
</p>
<p class="leafygreen-ui-1kp3ins">
If using x.509 authentication,
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.CAFile
</code>
must be specified unless using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.certificateKeyFile" 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-setting-net.tls.certificateKeyFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that contains both the TLS certificate
and key.
</p>
<p class="leafygreen-ui-1kp3ins">
On macOS or Windows, you can use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
setting to specify a certificate from the operating system's secure
certificate store instead of a PEM key file.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
certificateKeyFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
are mutually exclusive.
You can only specify one.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
On Linux/BSD, you must specify
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFile
</code>
</span>
</a>
when TLS is enabled.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
On Windows or macOS, you must specify either
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFile
</code>
</span>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
when TLS is enabled.
</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">
For Windows
<strong>
only
</strong>
, MongoDB does not support
encrypted PEM files. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
fails to start if
it encounters an encrypted PEM file. To securely store and
access a certificate for use with TLS on Windows,
use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
.
</span>
</a>
</p>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFilePassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.certificateKeyFilePassword" 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-setting-net.tls.certificateKeyFilePassword">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The password to de-crypt the certificate-key file (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
certificateKeyFile
</code>
</span>
</a>
). Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFilePassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFilePassword
</code>
</span>
</a>
option only if the
certificate-key file is encrypted. In all cases, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
redacts the
password from all logging and reporting output.
</p>
<p class="leafygreen-ui-1kp3ins">
On Linux/BSD, if the private key in the PEM file is encrypted and
you do not specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFilePassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFilePassword
</code>
</span>
</a>
option, MongoDB prompts for a passphrase.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-ssl-certificate-password">
TLS/SSL Certificate Passphrase.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
On macOS, if the private key in the PEM file is encrypted, you must
explicitly specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFilePassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFilePassword
</code>
</span>
</a>
option.
Alternatively, you can use a certificate from the secure system
store (see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
) instead of a PEM
key file or use an unencrypted PEM file.
</p>
<p class="leafygreen-ui-1kp3ins">
On Windows, MongoDB does not support encrypted certificates.
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
fails if it encounters an encrypted
PEM file. Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
instead.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.certificateSelector" 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-setting-net.tls.certificateSelector">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a certificate property in order to select a matching
certificate from the operating system's certificate store to use
for TLS/SSL. Available on Windows and macOS as an alternative to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFile
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateKeyFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
options are mutually
exclusive. You can only specify one.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
accepts an argument of the format
<code class="leafygreen-ui-1l06pbn">
<property>=<value>
</code>
where the property can be one of the following:
</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>
Property
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Value 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">
subject
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ASCII string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Subject name or common name on certificate
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
hex string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A sequence of bytes, expressed as hexadecimal, used to
identify a public key by its SHA-1 digest.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
is sometimes referred to as a
<code class="leafygreen-ui-1l06pbn">
fingerprint
</code>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
When using the system SSL certificate store, OCSP (Online
Certificate Status Protocol) is used to validate the revocation
status of certificates.
</p>
<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>
searches the operating system's secure
certificate store for the CA certificates required to validate the
full certificate chain of the specified TLS certificate.
Specifically, the secure certificate store must contain the root CA
and any intermediate CA certificates required to build the full
certificate chain to the TLS certificate.
</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 you use
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
and/or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
, we
<strong>
do not
</strong>
recommend
using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
</span>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
</span>
</a>
to
specify the root and intermediate CA certificate
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For example, if the TLS certificate was signed with a single root
CA certificate, the secure certificate store must contain that root
CA certificate. If the TLS certificate was signed with an
intermediate CA certificate, the secure certificate store must
contain the intermedia CA certificate
<em>
and
</em>
the root CA certificate.
</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 cannot use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/rotateCertificates/#mongodb-dbcommand-dbcmd.rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
command or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.rotateCertificates/#mongodb-method-db.rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</a>
shell method when using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterCertificateSelector" 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-setting-net.tls.clusterCertificateSelector">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a certificate property to select a matching certificate
from the operating system's secure certificate store to use for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-x509">
internal x.509 membership authentication.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Available on Windows and macOS as an alternative to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
options are mutually
exclusive. You can only specify one.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
accepts an argument of the format
<code class="leafygreen-ui-1l06pbn">
<property>=<value>
</code>
where the property can be one of the following:
</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>
Property
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Value 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">
subject
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ASCII string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Subject name or common name on certificate
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
hex string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A sequence of bytes, expressed as hexadecimal, used to
identify a public key by its SHA-1 digest.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
is sometimes referred to as a
<code class="leafygreen-ui-1l06pbn">
fingerprint
</code>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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>
searches the operating system's secure
certificate store for the CA certificates required to validate the
full certificate chain of the specified cluster certificate.
Specifically, the secure certificate store must contain the root CA
and any intermediate CA certificates required to build the full
certificate chain to the cluster certificate.
</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 you use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
and/or
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
, we
<strong>
do not
</strong>
recommend using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
</span>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
</span>
</a>
to specify
the root and intermediate CA certificate.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For example, if the cluster certificate was signed with a single root
CA certificate, the secure certificate store must contain that root
CA certificate. If the cluster certificate was signed with an
intermediate CA certificate, the secure certificate store must
contain the intermediate CA certificate
<em>
and
</em>
the root CA
certificate.
</p>
<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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
logs a warning on
connection if the presented x.509 certificate expires within
<code class="leafygreen-ui-1l06pbn">
30
</code>
days of the
<code class="leafygreen-ui-1l06pbn">
mongod/mongos
</code>
host system time.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterFile" 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-setting-net.tls.clusterFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that contains the x.509 certificate-key file
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/#std-label-x509-internal-authentication">
membership authentication
</a>
for the
cluster or replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
On macOS or Windows, you can use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
option to specify a
certificate from the operating system's secure certificate store
instead of a PEM key file.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
options are mutually
exclusive. You can only specify one.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterFile
</code>
</span>
</a>
does not specify the
<code class="leafygreen-ui-1l06pbn">
.pem
</code>
file
for internal cluster authentication or the alternative
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
, the cluster uses the
<code class="leafygreen-ui-1l06pbn">
.pem
</code>
file specified in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
certificateKeyFile
</code>
</span>
</a>
setting or the certificate returned by the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If using x.509 authentication,
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.CAFile
</code>
must be specified unless using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
.
</a>
</p>
<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>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
logs a warning on
connection if the presented x.509 certificate expires within
<code class="leafygreen-ui-1l06pbn">
30
</code>
days of the
<code class="leafygreen-ui-1l06pbn">
mongod/mongos
</code>
host system time.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
For Windows
<strong>
only
</strong>
, MongoDB does not support encrypted PEM files.
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
fails to start if it encounters an encrypted
PEM file. To securely store and access a certificate for use with
membership authentication on Windows, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
.
</span>
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterPassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterPassword" 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-setting-net.tls.clusterPassword">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The password to de-crypt the x.509 certificate-key file specified
with
<code class="leafygreen-ui-1l06pbn">
--sslClusterFile
</code>
. Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterPassword
</code>
</span>
</a>
option
only if the certificate-key file is encrypted. In all cases,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
redacts the
password from all logging and reporting output.
</p>
<p class="leafygreen-ui-1kp3ins">
On Linux/BSD, if the private key in the x.509 file is encrypted and
you do not specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterPassword
</code>
</span>
</a>
option,
MongoDB prompts for a passphrase.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-ssl-certificate-password">
TLS/SSL Certificate Passphrase.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
On macOS, if the private key in the x.509 file is encrypted, you
must explicitly specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterPassword
</code>
</span>
</a>
option. Alternatively, you can either use a certificate from the
secure system store (see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
)
instead of a cluster PEM file or use an unencrypted PEM file.
</p>
<p class="leafygreen-ui-1kp3ins">
On Windows, MongoDB does not support encrypted certificates. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
fails if it encounters an encrypted PEM file.
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterAuthX509
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterAuthX509" 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-setting-net.tls.clusterAuthX509">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New in version 7.0
</em>
.
</p>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n tls:\n clusterAuthX509:\n attributes: <string>\n extensionValue: <string>","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">tls:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthX509:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">attributes:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extensionValue:</span> <span class="lg-highlight-string"><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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterAuthX509.attributes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterAuthX509.attributes" 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-setting-net.tls.clusterAuthX509.attributes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 7.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies a set of X.509 Distinguished Name (DN) attributes and values that
the server expects cluster member nodes to contain in their certificate
subject names. This lets you use certificates that don't contain DC,
O, and OU values to authenticate cluster members.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
attributes
</code>
is set, MongoDB matches certificates using the DN
and ignores extension values.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterAuthX509.extensionValue
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterAuthX509.extensionValue" 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-setting-net.tls.clusterAuthX509.extensionValue">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 7.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies an extension value that corresponds to the MongoDB cluster
membership extension
<span class="leafygreen-ui-vm4wms" tabindex="0">
OID
</span>
, 1.3.6.1.4.1.34601.2.1.2, that the server expects cluster
member nodes to contain in their certificates. This allows you
to use certificates that don't contain DC, O, and OU values to authenticate
cluster members.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
extensionValue
</code>
is set, MongoDB matches certificates using
certificate extension values and ignores the Distinguished Name (DN).
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.CAFile" 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-setting-net.tls.CAFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that contains the root certificate chain
from the Certificate Authority. Specify the file name of the
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file using relative or absolute paths.
</p>
<dl>
<dt>
Windows/macOS Only
</dt>
<dd class="css-1ufxuu7">
If using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
and/or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
, do
<strong>
not
</strong>
use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
</span>
</a>
to specify the root and intermediate CA
certificates. Store all CA certificates required to validate the
full trust chain of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
and/or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
certificates
in the secure certificate store.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.clusterCAFile" 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-setting-net.tls.clusterCAFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that contains the root certificate chain
from the Certificate Authority used to validate the certificate
presented by a client establishing a connection. Specify the file
name of the
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file using relative or absolute paths.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
</span>
</a>
requires that
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
</span>
</a>
is set.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
</span>
</a>
does not specify the
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file for validating the certificate from a client establishing a
connection, the cluster uses the
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file specified in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CAFile
</code>
</span>
</a>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
</span>
</a>
lets you use separate Certificate
Authorities to verify the client to server and server to client
portions of the TLS handshake.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in 4.0, on macOS or Windows, you can use a certificate from
the operating system's secure store instead of a PEM key file. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
. When using the secure
store, you do not need to, but can, also specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
.
</span>
</a>
</p>
<dl>
<dt>
Windows/macOS Only
</dt>
<dd class="css-1ufxuu7">
If using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
and/or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
, do
<strong>
not
</strong>
use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCAFile
</code>
</span>
</a>
to specify the root and
intermediate CA certificates. Store all CA certificates required to
validate the full trust chain of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
and/or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.clusterCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.clusterCertificateSelector
</code>
</span>
</a>
certificates in the
secure certificate store.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.CRLFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.CRLFile" 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-setting-net.tls.CRLFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file that contains the Certificate Revocation
List. Specify the file name of the
<code class="file docutils literal">
<span class="pre">
.pem
</span>
</code>
file using relative or
absolute paths.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot specify
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CRLFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.CRLFile
</code>
</span>
</a>
on macOS. Instead, you can
use the system SSL certificate store, which uses OCSP (Online
Certificate Status Protocol) to validate the revocation status
of certificates. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.certificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.certificateSelector
</code>
</span>
</a>
to use the
system SSL certificate store.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To check for certificate revocation, MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ocspEnabled">
<code class="leafygreen-ui-1l06pbn">
enables
</code>
</a>
the use of OCSP
(Online Certificate Status Protocol) by default as an alternative
to specifying a CRL file or using the system SSL certificate
store.
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.allowConnectionsWithoutCertificates
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.allowConnectionsWithoutCertificates" 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-setting-net.tls.allowConnectionsWithoutCertificates">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, all clients must provide client TLS certificates. If
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
clients don't need to provide client certificates, but
<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>
encrypts the TLS/SSL connection.
</p>
<p class="leafygreen-ui-1kp3ins">
If a client provides a client certificate, regardless of what value you set
for
<code class="leafygreen-ui-1l06pbn">
net.tls.allowConnectionsWithoutCertificates
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
performs certificate validation using the root
certificate chain specified by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.CAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
CAFile
</code>
</span>
</a>
, or the system
CA store if
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsUseSystemCA">
<code class="leafygreen-ui-1l06pbn">
tlsUseSystemCA
</code>
</a>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
, and rejects
clients with invalid certificates.
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.allowConnectionsWithoutCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.allowConnectionsWithoutCertificates
</code>
</span>
</a>
option if you
have a mixed deployment that includes clients that do not or cannot present
certificates to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.allowInvalidCertificates
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.allowInvalidCertificates" 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-setting-net.tls.allowInvalidCertificates">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Enable or disable the validation checks for TLS certificates on other
servers in the cluster and allows the use of invalid certificates to
connect.
</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 you specify
<code class="leafygreen-ui-1l06pbn">
--tlsAllowInvalidCertificates
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.allowInvalidCertificates:
true
</code>
when using x.509 authentication, an invalid certificate is
only sufficient to establish a TLS connection but is
<em>
insufficient
</em>
for authentication.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When using the
<code class="leafygreen-ui-1l06pbn">
net.tls.allowInvalidCertificates
</code>
setting, MongoDB
logs a warning regarding the use of the invalid certificate.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-configure-mongod-mongos-for-tls-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/core/security-internal-authentication/#std-label-inter-process-auth">
Self-Managed Internal/Membership Authentication.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.allowInvalidHostnames
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.allowInvalidHostnames" 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-setting-net.tls.allowInvalidHostnames">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
net.tls.allowInvalidHostnames
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
, MongoDB disables
the validation of the hostnames in TLS certificates. This allows
<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>
to connect to other MongoDB
instances in the cluster, even if the hostname of their certificates does not
match the specified hostname.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/#std-label-configure-mongod-mongos-for-tls-ssl">
Configure
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
and
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
for TLS/SSL.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.disabledProtocols
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.disabledProtocols" 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-setting-net.tls.disabledProtocols">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Prevents a MongoDB server running with TLS from accepting
incoming connections that use a specific protocol or protocols. To
specify multiple protocols, use a comma separated list of protocols,
but do not use spaces after the commas. If you include a space before
a protocol name, the server interprets it as an unrecognized protocol
and doesn't start.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.disabledProtocols" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.disabledProtocols
</code>
</span>
</a>
recognizes the following protocols:
<code class="leafygreen-ui-1l06pbn">
TLS1_0
</code>
,
<code class="leafygreen-ui-1l06pbn">
TLS1_1
</code>
,
<code class="leafygreen-ui-1l06pbn">
TLS1_2
</code>
, and
<code class="leafygreen-ui-1l06pbn">
TLS1_3
</code>
.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
On macOS, you cannot disable
<code class="leafygreen-ui-1l06pbn">
TLS1_1
</code>
and leave both
<code class="leafygreen-ui-1l06pbn">
TLS1_0
</code>
and
<code class="leafygreen-ui-1l06pbn">
TLS1_2
</code>
enabled. You must disable at least one of the other
two, for example,
<code class="leafygreen-ui-1l06pbn">
TLS1_0,TLS1_1
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To list multiple protocols, specify as a comma separated list of
protocols without spaces after the commas. For example
<code class="leafygreen-ui-1l06pbn">
TLS1_0,TLS1_1
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specifying an unrecognized protocol or including a space after a
comma prevents the server from starting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The specified disabled protocols overrides any default disabled
protocols.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
MongoDB disables the use of TLS 1.0 if TLS 1.1+ is available on the
system. To enable TLS 1.0, specify
<code class="leafygreen-ui-1l06pbn">
none
</code>
to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.disabledProtocols" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.disabledProtocols
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Members of replica sets and sharded clusters must speak at least one
protocol in common.
</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-ssl/#std-label-ssl-disallow-protocols">
Disallow Protocols
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.FIPSMode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.FIPSMode" 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-setting-net.tls.FIPSMode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Enable or disable the use of the FIPS mode of the TLS
library 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. Your system must have a FIPS
compliant library to use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.FIPSMode" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.FIPSMode
</code>
</span>
</a>
option.
</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">
FIPS-compatible TLS/SSL is
available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-fips/">
Configure MongoDB for FIPS
</a>
for more information.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.tls.logVersions
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.tls.logVersions" 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-setting-net.tls.logVersions">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Instructs
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to log a
message when a client connects using a specified TLS version.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify either a single TLS version or a comma-separated list of
multiple TLS versions.
</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">
To instruct
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
to
log a message when a client connects using either TLS 1.2 or
TLS 1.3, set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-net.tls.logVersions" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
net.tls.logVersions
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
"TLS1_2,TLS1_3"
</code>
.
</p>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
net.compression
</code>
Option
<a class="headerlink leafygreen-ui-1kepx47" href="#net.compression-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="net.compression-option">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"net:\n compression:\n compressors: <string>","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">compression:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">compressors:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
net.compression.compressors
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-net.compression.compressors" 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-setting-net.compression.compressors">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: snappy,zstd,zlib
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the default compressor(s) to use for
communication between this
<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>
instance and:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
other members of the deployment if the instance is part of a replica set or a sharded cluster
</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/mongodb-shell/#mongodb-binary-bin.mongosh" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
drivers that support the
<code class="leafygreen-ui-1l06pbn">
OP_COMPRESSED
</code>
message format.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports the following compressors:
</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-snappy">
snappy
</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-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 disable network compression, set the value to
<code class="leafygreen-ui-1l06pbn">
disabled
</code>
.
</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">
Messages are compressed when both parties enable network
compression. Otherwise, messages between the parties are
uncompressed.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you specify multiple compressors, then the order in which you list
the compressors matter as well as the communication initiator. For
example, if
<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>
specifies the following network
compressors
<code class="leafygreen-ui-1l06pbn">
zlib,snappy
</code>
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>
specifies
<code class="leafygreen-ui-1l06pbn">
snappy,zlib
</code>
, messages between
<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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
uses
<code class="leafygreen-ui-1l06pbn">
zlib
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If the parties do not share at least one common compressor, messages
between the parties are uncompressed. For example, if
<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>
specifies the network compressor
<code class="leafygreen-ui-1l06pbn">
zlib
</code>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
specifies
<code class="leafygreen-ui-1l06pbn">
snappy
</code>
, messages
between
<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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
are not
compressed.
</p>
</dd>
</dl>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
security
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#security-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="security-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n keyFile: <string>\n clusterAuthMode: <string>\n authorization: <string>\n transitionToAuth: <boolean>\n javascriptEnabled: <boolean>\n redactClientLogData: <boolean>\n clusterIpSourceAllowlist:\n - <string>\n sasl:\n hostName: <string>\n serviceName: <string>\n saslauthdSocketPath: <string>\n enableEncryption: <boolean>\n encryptionCipherMode: <string>\n encryptionKeyFile: <string>\n kmip:\n keyIdentifier: <string>\n rotateMasterKey: <boolean>\n serverName: <string>\n port: <string>\n clientCertificateFile: <string>\n clientCertificatePassword: <string>\n clientCertificateSelector: <string>\n serverCAFile: <string>\n connectRetries: <int>\n connectTimeoutMS: <int>\n ldap:\n servers: <string>\n bind:\n method: <string>\n saslMechanisms: <string>\n queryUser: <string>\n queryPassword: <string>\n useOSDefaults: <boolean>\n transportSecurity: <string>\n timeoutMS: <int>\n userToDNMapping: <string>\n authz:\n queryTemplate: <string>\n validateLDAPServerConfig: <boolean>","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"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterAuthMode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authorization:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transitionToAuth:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">javascriptEnabled:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">redactClientLogData:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clusterIpSourceAllowlist:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-bullet">-</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sasl:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hostName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serviceName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">saslauthdSocketPath:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">enableEncryption:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptionCipherMode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptionKeyFile:</span> <span class="lg-highlight-string"><string></span></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">keyIdentifier:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">rotateMasterKey:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serverName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificateFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificatePassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serverCAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">connectRetries:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">connectTimeoutMS:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ldap:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">servers:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bind:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">saslMechanisms:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryUser:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryPassword:</span> <span class="lg-highlight-string"><string</span> <span class="lg-highlight-string">|</span> <span class="lg-highlight-string">array></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">useOSDefaults:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transportSecurity:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeoutMS:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">userToDNMapping:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authz:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryTemplate:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">validateLDAPServerConfig:</span> <span class="lg-highlight-string"><boolean></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.keyFile" 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-setting-security.keyFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The path to a key file that stores the shared secret
that MongoDB instances use to authenticate to each other in 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>
.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.keyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
keyFile
</code>
</span>
</a>
implies
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.authorization" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.authorization
</code>
</span>
</a>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
Self-Managed Internal/Membership Authentication
</a>
for more
information.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.clusterAuthMode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.clusterAuthMode" 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-setting-security.clusterAuthMode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: keyFile
</p>
<p class="leafygreen-ui-1kp3ins">
The authentication mode used for cluster authentication. If you use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-x509-member-authentication/#std-label-x509-internal-authentication">
internal x.509 authentication
</a>
,
specify so here. This option can have one of the following values:
</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>
Value
</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">
keyFile
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Use a keyfile for authentication.
Accept only keyfiles.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sendKeyFile
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
For rolling upgrade purposes. Send a keyfile for
authentication but can accept both keyfiles and x.509
certificates.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sendX509
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
For rolling upgrade purposes. Send the x.509 certificate for
authentication but can accept both keyfiles and x.509
certificates.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
x509
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Recommended. Send the x.509 certificate for authentication and
accept only x.509 certificates.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.CAFile
</code>
is not
specified and you are not using x.509 authentication, you must set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsUseSystemCA">
<code class="leafygreen-ui-1l06pbn">
tlsUseSystemCA
</code>
</a>
parameter to
<code class="leafygreen-ui-1l06pbn">
true
</code>
. This makes MongoDB use
the system-wide CA certificate store when connecting to a TLS-enabled server.
</p>
<p class="leafygreen-ui-1kp3ins">
If using x.509 authentication,
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
or
<code class="leafygreen-ui-1l06pbn">
tls.CAFile
</code>
must be specified unless using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about TLS and MongoDB, 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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.authorization
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.authorization" 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-setting-security.authorization">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: disabled
</p>
<p class="leafygreen-ui-1kp3ins">
Enable or disable Role-Based Access Control (RBAC) to govern each
user's access to database resources and operations.
</p>
<p class="leafygreen-ui-1kp3ins">
Set this option to one of the following:
</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>
Value
</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">
enabled
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A user can access only the database resources and actions for
which they have been granted privileges.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
disabled
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A user can access any database and perform any action.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/">
Role-Based Access Control in Self-Managed Deployments
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.authorization" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.authorization
</code>
</span>
</a>
setting is available only for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.transitionToAuth" 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-setting-security.transitionToAuth">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Allows 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>
to accept and
create authenticated and non-authenticated connections to and from other
<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 in the deployment.
Used for performing rolling transition of replica sets or sharded clusters
from a no-auth configuration to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
internal authentication
</a>
.
Requires specifying a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
internal authentication
</a>
mechanism such as
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.keyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.keyFile
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For example, if using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-internal-auth-keyfile">
keyfiles
</a>
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
internal authentication
</a>
, 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>
creates
an authenticated connection with any
<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>
in the deployment using a matching keyfile. If the security mechanisms do
not match, 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>
utilizes a non-authenticated connection instead.
</p>
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
running with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.transitionToAuth" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</span>
</a>
does not enforce
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
user access
controls
</a>
. Users may connect to your deployment without any
access control checks and perform read, write, and administrative operations.
</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
<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>
running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-internal-authentication/#std-label-inter-process-auth">
internal authentication
</a>
and
<em>
without
</em>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.transitionToAuth" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
</span>
</a>
requires clients to connect
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
user access controls
</a>
. Update clients 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using the appropriate
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-users/#std-label-users">
user
</a>
prior to restarting
<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>
without
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.transitionToAuth" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.transitionToAuth
</code>
.
</span>
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.javascriptEnabled" 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-setting-security.javascriptEnabled">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Server-side JavaScript Deprecated
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, server-side JavaScript functions
(
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
) are
deprecated. MongoDB logs a warning when you run these functions.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce">
Map-reduce
</a>
is deprecated starting in MongoDB
5.0.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Enables or disables
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/server-side-javascript/">
server-side JavaScript execution
</a>
. When disabled, you cannot use
operations that perform server-side execution of JavaScript code,
such as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
query operator,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
command,
<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>
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not use these operations, disable server-side scripting.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.javascriptEnabled" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
</span>
</a>
is available for both
<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>
. In earlier versions, the
setting is only available for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.redactClientLogData" 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-setting-security.redactClientLogData">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
running with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.redactClientLogData" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</span>
</a>
redacts any message accompanying a given
log event before logging. This prevents 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>
from writing
potentially sensitive data stored on the database to the diagnostic log.
Metadata such as error or operation codes, line numbers, and source file
names are still visible in the logs.
</p>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.redactClientLogData" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</span>
</a>
in conjunction with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/">
Encryption at Rest
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/">
TLS/SSL (Transport Encryption)
</a>
to assist compliance with
regulatory requirements.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, a MongoDB deployment might store Personally Identifiable
Information (PII) in one or more collections. 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>
logs events
such as those related to CRUD operations, sharding metadata, etc. It is
possible that 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>
may expose PII as a part of these logging
operations. A
<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>
running with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.redactClientLogData" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</span>
</a>
removes any message
accompanying these events before being output to the log, effectively
removing the PII.
</p>
<p class="leafygreen-ui-1kp3ins">
Diagnostics on a
<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>
running with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.redactClientLogData" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</span>
</a>
may be more difficult
due to the lack of data related to a log event. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/monitoring/#std-label-monitoring-log-redaction">
process logging
</a>
manual page for an
example of the effect of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.redactClientLogData" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.redactClientLogData
</code>
</span>
</a>
on log output.
</p>
<p class="leafygreen-ui-1kp3ins">
On 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.redactClientLogData">
<code class="leafygreen-ui-1l06pbn">
redactClientLogData
</code>
</a>
parameter to configure this setting.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.clusterIpSourceAllowlist" 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-setting-security.clusterIpSourceAllowlist">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: list
</p>
<div>
<p>
<em>
New in version 5.0
</em>
.
</p>
</div>
<div>
<p>
<em>
Changed in version 5.2
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
A list of IP addresses/CIDR (
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4632" rel="noopener noreferrer">
<span>
Classless Inter-Domain Routing
</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>
) ranges against which the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
validates authentication requests from other
members of the replica set and, if part of a sharded cluster, 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. The
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
verifies
that the originating IP is either explicitly in the list or belongs
to a CIDR range in the list. If the IP address is not present, the
server does not authenticate the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
or
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
has no effect on a
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
started without
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.2, you can configure
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
on a running
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
or
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
This example updates
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
during runtime to include the IP addresses
<code class="leafygreen-ui-1l06pbn">
"1.1.1.1/24"
</code>
,
<code class="leafygreen-ui-1l06pbn">
"2.2.2.2/16"
</code>
, and
<code class="leafygreen-ui-1l06pbn">
"3.3.3.3"
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n setParameter: 1,\n \"clusterIpSourceAllowlist\": [\"1.1.1.1/24\", \"2.2.2.2/16\", \"3.3.3.3\"]\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"> <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-string">"clusterIpSourceAllowlist"</span>: [<span class="lg-highlight-string">"1.1.1.1/24"</span>, <span class="lg-highlight-string">"2.2.2.2/16"</span>, <span class="lg-highlight-string">"3.3.3.3"</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">
This example updates
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
during
runtime to exclude all IP addresses:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" db.adminCommand( {\n setParameter: 1,\n \"clusterIpSourceAllowlist\": null\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">setParameter</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clusterIpSourceAllowlist"</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>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
has no effect on a
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
started without
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
requires specifying each
IPv4/6 address or Classless Inter-Domain Routing
(
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4632" rel="noopener noreferrer">
<span>
CIDR
</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>
) range as a YAML list:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n clusterIpSourceAllowlist:\n - 192.0.2.0/24\n - 127.0.0.1\n - ::1","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">clusterIpSourceAllowlist:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-bullet">-</span> <span class="lg-highlight-number">192.0</span><span class="lg-highlight-number">.2</span><span class="lg-highlight-number">.0</span><span class="lg-highlight-string">/24</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-bullet">-</span> <span class="lg-highlight-number">127.0</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-bullet">-</span> <span class="lg-highlight-string">::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-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Ensure
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
includes the
IP address
<em>
or
</em>
CIDR ranges that include the IP address of each
replica set member or
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
in the deployment to
ensure healthy communication between cluster components.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceWhitelist
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.clusterIpSourceWhitelist" 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-setting-security.clusterIpSourceWhitelist">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: list
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Deprecated in version 5.0:
</em>
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.clusterIpSourceAllowlist" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceAllowlist
</code>
</span>
</a>
instead.
</p>
<p class="leafygreen-ui-1kp3ins">
A list of IP addresses/CIDR (
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4632" rel="noopener noreferrer">
<span>
Classless Inter-Domain Routing
</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>
) ranges against which the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
validates authentication requests from other members of
the replica set and, if part of a sharded cluster, 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. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
verifies that the originating IP is
either explicitly in the list or belongs to a CIDR range in the list. If the
IP address is not present, the server does not authenticate 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>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.clusterIpSourceWhitelist" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceWhitelist
</code>
</span>
</a>
has no effect on 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 without
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.clusterIpSourceWhitelist" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceWhitelist
</code>
</span>
</a>
requires specifying each IPv4/6 address or Classless Inter-Domain
Routing (
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4632" rel="noopener noreferrer">
<span>
CIDR
</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>
) range as a YAML list:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n clusterIpSourceWhitelist:\n - 192.0.2.0/24\n - 127.0.0.1\n - ::1","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">clusterIpSourceWhitelist:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-bullet">-</span> <span class="lg-highlight-number">192.0</span><span class="lg-highlight-number">.2</span><span class="lg-highlight-number">.0</span><span class="lg-highlight-string">/24</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-bullet">-</span> <span class="lg-highlight-number">127.0</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-bullet">-</span> <span class="lg-highlight-string">::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-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Ensure
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.clusterIpSourceWhitelist" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.clusterIpSourceWhitelist
</code>
</span>
</a>
includes the IP address
<em>
or
</em>
CIDR ranges that include the
IP address of each replica set member or
<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
deployment to ensure healthy communication between cluster components.
</p>
</div>
</div>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-encryption-key-management-conf-options">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Key Management Configuration Options
<a class="headerlink leafygreen-ui-1kepx47" href="#key-management-configuration-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="key-management-configuration-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n enableEncryption: <boolean>\n encryptionCipherMode: <string>\n encryptionKeyFile: <string>\n kmip:\n keyIdentifier: <string>\n rotateMasterKey: <boolean>\n serverName: <string>\n port: <string>\n clientCertificateFile: <string>\n clientCertificatePassword: <string>\n clientCertificateSelector: <string>\n serverCAFile: <string>\n connectRetries: <int>\n connectTimeoutMS: <int>\n activateKeys: <boolean>\n keyStatePollingSeconds: <int>","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">enableEncryption:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptionCipherMode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptionKeyFile:</span> <span class="lg-highlight-string"><string></span></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">keyIdentifier:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">rotateMasterKey:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serverName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">port:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificateFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificatePassword:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">clientCertificateSelector:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serverCAFile:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">connectRetries:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">connectTimeoutMS:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">activateKeys:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyStatePollingSeconds:</span> <span class="lg-highlight-string"><int></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.enableEncryption
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.enableEncryption" 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-setting-security.enableEncryption">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Enables encryption for the WiredTiger storage engine. You must set
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to pass in encryption keys and configurations.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.encryptionCipherMode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.encryptionCipherMode" 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-setting-security.encryptionCipherMode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
AES256-CBC
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
The cipher mode to use for encryption at rest:
</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">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
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="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
AES256-CBC
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
256-bit Advanced Encryption Standard in Cipher Block Chaining Mode
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
AES256-GCM
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
256-bit Advanced Encryption Standard in Galois/Counter Mode
</p>
<p class="leafygreen-ui-1kp3ins">
Available only on Linux.
</p>
<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>
</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>
Enterprise Feature
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise only.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.encryptionKeyFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.encryptionKeyFile" 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-setting-security.encryptionKeyFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The path to the local keyfile when managing keys through a process
<em>
other
than
</em>
KMIP. Only set when managing keys through a process other than KMIP.
If data is already encrypted using KMIP, MongoDB throws an error.
</p>
<p class="leafygreen-ui-1kp3ins">
Requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.enableEncryption" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.enableEncryption
</code>
</span>
</a>
to be
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.keyIdentifier
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.keyIdentifier" 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-setting-security.kmip.keyIdentifier">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Unique KMIP identifier for an existing key within the KMIP server.
Include to use the key associated with the identifier as the system
key. You can only use the setting the first time you enable
encryption for 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. Requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.enableEncryption" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.enableEncryption
</code>
</span>
</a>
to be true.
</p>
<p class="leafygreen-ui-1kp3ins">
If unspecified, MongoDB requests that the KMIP server create a
new key to utilize as the system key.
</p>
<p class="leafygreen-ui-1kp3ins">
If the KMIP server cannot locate a key with the specified identifier
or the data is already encrypted with a key, MongoDB throws an error.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.rotateMasterKey" 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-setting-security.kmip.rotateMasterKey">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
If true, rotate the master key and re-encrypt the internal
keystore.
</p>
<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-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/rotate-encryption-key/#std-label-kmip-master-key-rotation">
KMIP Master Key Rotation
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.serverName" 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-setting-security.kmip.serverName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Hostname or IP address of the KMIP server to connect to. Requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.enableEncryption" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.enableEncryption
</code>
</span>
</a>
to be true.
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify multiple KMIP servers as a comma-separated list, for example
<code class="leafygreen-ui-1l06pbn">
server1.example.com,server2.example.com
</code>
. On startup, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
attempts to establish a connection to each
server in the order listed, and selects the first server to
which it can successfully establish a connection. KMIP server
selection occurs only at startup.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
verifies the connection to the KMIP server on startup.
</p>
<p class="leafygreen-ui-1kp3ins">
The server name specified in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--kmipServerName">
<code class="leafygreen-ui-1l06pbn">
--kmipServerName
</code>
</a>
must match either the Subject Alternative
Name
<code class="leafygreen-ui-1l06pbn">
SAN
</code>
or the Common Name
<code class="leafygreen-ui-1l06pbn">
CN
</code>
on the certificate presented by
the KMIP server.
<code class="leafygreen-ui-1l06pbn">
SAN
</code>
can be a system name or an IP address.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
SAN
</code>
is present,
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
does not try to match against
<code class="leafygreen-ui-1l06pbn">
CN
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If the hostname or IP address of the KMIP server does does not match
either
<code class="leafygreen-ui-1l06pbn">
SAN
</code>
or
<code class="leafygreen-ui-1l06pbn">
CN
</code>
,
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
does not start.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 4.2, when performing comparison of SAN, MongoDB
supports comparison of DNS names or IP addresses. In previous versions,
MongoDB only supports comparisons of DNS names.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.port
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.port" 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-setting-security.kmip.port">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 5696
</p>
<p class="leafygreen-ui-1kp3ins">
Port number to use to communicate with the KMIP server. Requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.serverName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverName
</code>
</span>
</a>
. Requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.enableEncryption" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.enableEncryption
</code>
</span>
</a>
to be true.
</p>
<p class="leafygreen-ui-1kp3ins">
If specifying multiple KMIP servers with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.serverName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverName
</code>
</span>
</a>
, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
uses the port specified with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.port" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.port
</code>
</span>
</a>
for all
provided KMIP servers.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.clientCertificateFile" 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-setting-security.kmip.clientCertificateFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Path to the
<code class="leafygreen-ui-1l06pbn">
.pem
</code>
file used to authenticate MongoDB to the KMIP
server. The specified
<code class="leafygreen-ui-1l06pbn">
.pem
</code>
file must contain both the TLS/SSL
certificate and key.
</p>
<p class="leafygreen-ui-1kp3ins">
To use this setting, you must also specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.serverName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverName
</code>
</span>
</a>
setting.
</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">
Enabling encryption using a KMIP server on Windows fails when using
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateFile
</code>
and the KMIP server enforces TLS 1.2.
</p>
<p class="leafygreen-ui-1kp3ins">
To enable encryption at rest with KMIP on Windows, you must:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Import the client certificate into the Windows Certificate Store.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateSelector
</code>
</span>
</a>
option.
</p>
</li>
</ul>
</div>
</div>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificatePassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.clientCertificatePassword" 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-setting-security.kmip.clientCertificatePassword">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The password to decrypt the client certificate (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateFile
</code>
</span>
</a>
), used to
authenticate MongoDB to the KMIP server. Use the option only if the
certificate is encrypted.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateSelector
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.clientCertificateSelector" 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-setting-security.kmip.clientCertificateSelector">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 5.0
</em>
: Available on Windows and macOS as an alternative to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.kmip.clientCertificateFile">
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateFile
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateSelector
</code>
</span>
</a>
options are mutually exclusive. You can only
specify one.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies a certificate property in order to select a matching
certificate from the operating system's certificate store to
authenticate MongoDB to the KMIP server.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateSelector
</code>
</span>
</a>
accepts an argument of the format
<code class="leafygreen-ui-1l06pbn">
<property>=<value>
</code>
where the property can be one of the following:
</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>
Property
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Value 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">
subject
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ASCII string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Subject name or common name on certificate
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
hex string
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A sequence of bytes, expressed as hexadecimal, used to
identify a public key by its SHA-1 digest.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
is sometimes referred to as a
<code class="leafygreen-ui-1l06pbn">
fingerprint
</code>
.
</p>
</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>
Enterprise Feature
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise only.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverCAFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.serverCAFile" 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-setting-security.kmip.serverCAFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Path to CA File. Used for validating secure client connection to
KMIP server.
</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 4.0, on macOS or Windows, you can use a certificate
from the operating system's secure store instead of a PEM key
file. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.clientCertificateSelector" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.clientCertificateSelector
</code>
</span>
</a>
. When using the secure store, you do not
need to, but can, also specify the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.serverCAFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.serverCAFile
</code>
.
</span>
</a>
</p>
</div>
</div>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.connectRetries
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.connectRetries" 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-setting-security.kmip.connectRetries">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
How many times to retry the initial connection to the KMIP server.
Use together with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.connectTimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
connectTimeoutMS
</code>
</span>
</a>
to
control how long the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
waits for a response
between each retry.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.connectTimeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.connectTimeoutMS" 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-setting-security.kmip.connectTimeoutMS">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 5000
</p>
<p class="leafygreen-ui-1kp3ins">
Timeout in milliseconds to wait for a response from the KMIP server.
If the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.connectRetries" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
connectRetries
</code>
</span>
</a>
setting is specified,
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
waits up to the value specified with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.connectTimeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
connectTimeoutMS
</code>
</span>
</a>
for each retry.
</p>
<p class="leafygreen-ui-1kp3ins">
Value must be
<code class="leafygreen-ui-1l06pbn">
1000
</code>
or greater.
</p>
<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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.activateKeys
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.activateKeys" 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-setting-security.kmip.activateKeys">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Activates all newly created KMIP keys upon creation and then periodically
checks those keys are in an active state.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
security.kmip.activateKeys
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
and you have existing keys
on a KMIP server, the key must be activated first or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
node fails to start.
</p>
<p class="leafygreen-ui-1kp3ins">
If the key being used by the mongod transitions into a non-active state,
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
node shuts down unless
<code class="leafygreen-ui-1l06pbn">
kmipActivateKeys
</code>
is
false. To ensure you have an active key, rotate the KMIP master key by
using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.kmip.rotateMasterKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.kmip.rotateMasterKey
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.keyStatePollingSeconds
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.keyStatePollingSeconds" 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-setting-security.kmip.keyStatePollingSeconds">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 900 seconds
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Frequency in seconds at which mongod polls the KMIP server for active keys.
</p>
<p class="leafygreen-ui-1kp3ins">
To disable disable polling, set the value to
<code class="leafygreen-ui-1l06pbn">
-1
</code>
.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.kmip.useLegacyProtocol
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.kmip.useLegacyProtocol" 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-setting-security.kmip.useLegacyProtocol">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<div>
<p>
<em>
New in version 7.0
</em>
: (and 6.0.6)
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
uses KMIP protocol version 1.0 or 1.1 instead
of the default version. The default KMIP protocol is version 1.2.
</p>
<p class="leafygreen-ui-1kp3ins">
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log">
audit log encryption
</a>
with KMIP version 1.0 or 1.1, you must specify
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.auditEncryptKeyWithKMIPGet">
<code class="leafygreen-ui-1l06pbn">
auditEncryptKeyWithKMIPGet
</code>
</a>
at startup.
</p>
<p class="leafygreen-ui-1kp3ins">
To use KMIP protocol version 1.0 or 1.1, substitute your local values
and add an entry like this to your
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
configuration file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n enableEncryption: true\n kmip:\n serverName: \"mdbhost.somecompany.com\"\n serverCAFile: \"security/libs/trusted-ca.pem\"\n clientCertificateFile: \"security/libs/trusted-client.pem\"\n useLegacyProtocol: 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">security:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> enableEncryption: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> kmip:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> serverName: <span class="lg-highlight-string">"mdbhost.somecompany.com"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> serverCAFile: <span class="lg-highlight-string">"security/libs/trusted-ca.pem"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> clientCertificateFile: <span class="lg-highlight-string">"security/libs/trusted-client.pem"</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> useLegacyProtocol: <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>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-security.sasl.options">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
security.sasl
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#security.sasl-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="security.sasl-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n sasl:\n hostName: <string>\n serviceName: <string>\n saslauthdSocketPath: <string>","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">sasl:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hostName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serviceName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">saslauthdSocketPath:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.sasl.hostName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.sasl.hostName" 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-setting-security.sasl.hostName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
A fully qualified server domain name for the purpose of configuring SASL
and Kerberos authentication. The SASL hostname overrides the hostname
only for the configuration of SASL and Kerberos.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.sasl.serviceName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.sasl.serviceName" 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-setting-security.sasl.serviceName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
Registered name of the service using SASL. This option allows you to
override the default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/">
Kerberos
</a>
service name component of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/">
Kerberos
</a>
principal name, on a per-instance basis. If unspecified, the default
value is
<code class="leafygreen-ui-1l06pbn">
mongodb
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB permits setting this option only at startup. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
can not change this setting.
</p>
<p class="leafygreen-ui-1kp3ins">
This option is available only in MongoDB Enterprise.
</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">
Ensure that your driver supports alternate service names.
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>
and other MongoDB tools to
connect to the new
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.sasl.serviceName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
serviceName
</code>
</span>
</a>
, see the
<code class="leafygreen-ui-1l06pbn">
gssapiServiceName
</code>
option.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.sasl.saslauthdSocketPath
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.sasl.saslauthdSocketPath" 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-setting-security.sasl.saslauthdSocketPath">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The path to the UNIX domain socket file for
<code class="leafygreen-ui-1l06pbn">
saslauthd
</code>
.
</p>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-security.ldap.options">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
security.ldap
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#security.ldap-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="security.ldap-options">
</div>
</a>
</h4>
<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 8.0, LDAP authentication and authorization is
deprecated. LDAP is available and will continue to operate without
changes throughout the lifetime of MongoDB 8. LDAP will be removed in a
future major release.
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/LDAP-deprecation/#std-label-ldap-deprecation">
LDAP Deprecation.
</a>
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"security:\n ldap:\n servers: <string>\n bind:\n method: <string>\n saslMechanisms: <string>\n queryUser: <string>\n queryPassword: <string>\n useOSDefaults: <boolean>\n transportSecurity: <string>\n timeoutMS: <int>\n retryCount: <int>\n userToDNMapping: <string>\n authz:\n queryTemplate: <string>\n validateLDAPServerConfig: <boolean>","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">ldap:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">servers:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bind:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">saslMechanisms:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryUser:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryPassword:</span> <span class="lg-highlight-string"><string</span> <span class="lg-highlight-string">|</span> <span class="lg-highlight-string">array></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">useOSDefaults:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transportSecurity:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timeoutMS:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">retryCount:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">userToDNMapping:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">authz:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryTemplate:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">validateLDAPServerConfig:</span> <span class="lg-highlight-string"><boolean></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.servers
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.servers" 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-setting-security.ldap.servers">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The LDAP server against which 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>
authenticates users or
determines what actions a user is authorized to perform on a given
database. If the LDAP server specified has any replicated instances,
you may specify the host and port of each replicated server in a
comma-delimited list.
</p>
<p class="leafygreen-ui-1kp3ins">
If your LDAP infrastructure partitions the LDAP directory over multiple LDAP
servers, specify
<em>
one
</em>
LDAP server or any of its replicated instances to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.servers" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.ldap.servers
</code>
</span>
</a>
. MongoDB supports following LDAP referrals as defined in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.rfc-editor.org/rfc/rfc4511.txt" rel="noopener noreferrer">
<span>
RFC 4511
4.1.10
</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>
. Do not use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.servers" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.ldap.servers
</code>
</span>
</a>
for listing every LDAP server in your infrastructure.
</p>
<p class="leafygreen-ui-1kp3ins">
You can prefix LDAP servers with
<code class="leafygreen-ui-1l06pbn">
srv:
</code>
and
<code class="leafygreen-ui-1l06pbn">
srv_raw:
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If your connection string specifies
<code class="leafygreen-ui-1l06pbn">
"srv:<DNS_NAME>"
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
verifies that
<code class="leafygreen-ui-1l06pbn">
"_ldap._tcp.gc._msdcs.<DNS_NAME>"
</code>
exists for SRV to
support Active Directory. If not found,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
verifies that
<code class="leafygreen-ui-1l06pbn">
"_ldap._tcp.<DNS_NAME>"
</code>
exists for SRV. If an SRV record cannot be
found,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
warns you to use
<code class="leafygreen-ui-1l06pbn">
"srv_raw:<DNS_NAME>"
</code>
instead.
</p>
<p class="leafygreen-ui-1kp3ins">
If your connection string specifies
<code class="leafygreen-ui-1l06pbn">
"srv_raw:<DNS_NAME>"
</code>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
performs an SRV record lookup for
<code class="leafygreen-ui-1l06pbn">
"<DNS NAME>"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If unset,
<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>
cannot use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap/">
LDAP authentication or authorization.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.queryUser
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.bind.queryUser" 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-setting-security.ldap.bind.queryUser">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The identity with which
<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>
binds as, when connecting to or
performing queries on an LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
Only required if any of the following are true:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap-external/#std-label-security-ldap-external">
LDAP authorization.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using an LDAP query for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.ldap.userToDNMapping
</code>
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The LDAP server disallows anonymous binds
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If unset,
<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>
does not
attempt to bind to the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</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">
Windows MongoDB deployments can use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
instead of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
</span>
</a>
. You cannot specify
both
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
at the same time.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.queryPassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.bind.queryPassword" 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-setting-security.ldap.bind.queryPassword">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string or array
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The password used to bind to an LDAP server when using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
. You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
</span>
</a>
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If not set,
<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>
does not attempt to
bind to the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
You can configure this setting on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
ldapQueryPassword
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
command accepts either a
string or an array of strings. If
<code class="leafygreen-ui-1l06pbn">
ldapQueryPassword
</code>
is set to an array,
MongoDB tries each password in order until one succeeds. Use a password array
to roll over the LDAP account password without downtime.
</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">
Windows MongoDB deployments can use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
instead of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
</span>
</a>
. You cannot specify both
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
at the same time.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.useOSDefaults
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.bind.useOSDefaults" 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-setting-security.ldap.bind.useOSDefaults">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise for the Windows platform only.
</p>
<p class="leafygreen-ui-1kp3ins">
Allows
<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>
to authenticate, or bind, using your Windows login
credentials when connecting to the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
Only required if:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap-external/#std-label-security-ldap-external">
LDAP authorization.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using an LDAP query for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
username transformation
</code>
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The LDAP server disallows anonymous binds
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
to replace
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.method
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.bind.method" 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-setting-security.ldap.bind.method">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: simple
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The method
<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>
uses to authenticate to an LDAP server.
Use with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryUser
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.queryPassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
queryPassword
</code>
</span>
</a>
to
connect to the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.method" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
method
</code>
</span>
</a>
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">
simple
</code>
-
<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>
uses simple authentication.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sasl
</code>
-
<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>
uses SASL protocol for authentication
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you specify
<code class="leafygreen-ui-1l06pbn">
sasl
</code>
, you can configure the available SASL mechanisms
using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.saslMechanisms" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.saslMechanisms
</code>
</span>
</a>
.
<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>
defaults to
using
<code class="leafygreen-ui-1l06pbn">
DIGEST-MD5
</code>
mechanism.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.bind.saslMechanisms
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.bind.saslMechanisms" 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-setting-security.ldap.bind.saslMechanisms">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: DIGEST-MD5
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
A comma-separated list of SASL mechanisms
<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>
can
use when authenticating to the LDAP server. 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>
and the
LDAP server must agree on at least one mechanism. 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>
dynamically loads any SASL mechanism libraries installed on the host
machine at runtime.
</p>
<p class="leafygreen-ui-1kp3ins">
Install and configure the appropriate libraries for the selected
SASL mechanism(s) on both 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>
host and the remote
LDAP server host. Your operating system may include certain SASL
libraries by default. Defer to the documentation associated with each
SASL mechanism for guidance on installation and configuration.
</p>
<p class="leafygreen-ui-1kp3ins">
If using the
<code class="leafygreen-ui-1l06pbn">
GSSAPI
</code>
SASL mechanism for use with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-security-kerberos">
Kerberos Authentication on Self-Managed Deployments
</a>
, verify the following for 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>
host machine:
</p>
<dl>
<dt>
<code class="leafygreen-ui-1l06pbn">
Linux
</code>
</dt>
<dd class="css-1ufxuu7">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
KRB5_CLIENT_KTNAME
</code>
environment
variable resolves to the name of the client
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-keytab-files">
Linux Keytab Files
</a>
for the host machine. For more on Kerberos environment
variables, please defer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://web.mit.edu/kerberos/krb5-1.13/doc/admin/env_variables.html" rel="noopener noreferrer">
<span>
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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The client keytab includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/kerberos/#std-label-kerberos-user-principal">
User Principal
</a>
for 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>
to use when
connecting to the LDAP server and execute LDAP queries.
</p>
</li>
</ul>
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
Windows
</code>
</dt>
<dd class="css-1ufxuu7">
If connecting to an Active Directory server, the Windows
Kerberos configuration automatically generates a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa380510(v=vs.85).aspx" rel="noopener noreferrer">
<span>
Ticket-Granting-Ticket
</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 the user logs onto the system. Set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.useOSDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
useOSDefaults
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to allow
<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>
to use the generated credentials when
connecting to the Active Directory server and execute queries.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.bind.method" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
method
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
sasl
</code>
to use this option.
</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 a complete list of SASL mechanisms see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.iana.org/assignments/sasl-mechanisms/sasl-mechanisms.xhtml" rel="noopener noreferrer">
<span>
IANA listing
</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>
.
Defer to the documentation for your LDAP or Active Directory
service for identifying the SASL mechanisms compatible with the
service.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB is not a source of SASL mechanism libraries, nor
is the MongoDB documentation a definitive source for
installing or configuring any given SASL mechanism. For
documentation and support, defer to the SASL mechanism
library vendor or owner.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on SASL, defer to the following resources:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For Linux, please see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.cyrusimap.org/sasl/" rel="noopener noreferrer">
<span>
Cyrus SASL 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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For Windows, please see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://msdn.microsoft.com/en-us/library/cc223500.aspx" rel="noopener noreferrer">
<span>
Windows SASL 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>
</p>
</li>
</ul>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.transportSecurity
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.transportSecurity" 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-setting-security.ldap.transportSecurity">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: tls
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
By default,
<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>
creates a TLS/SSL secured connection to the LDAP
server.
</p>
<p class="leafygreen-ui-1kp3ins">
For Linux deployments, you must configure the appropriate TLS Options in
<code class="leafygreen-ui-1l06pbn">
/etc/openldap/ldap.conf
</code>
file. Your operating system's package manager
creates this file as part of the MongoDB Enterprise installation, through the
<code class="leafygreen-ui-1l06pbn">
libldap
</code>
dependency. See the documentation for
<code class="leafygreen-ui-1l06pbn">
TLS Options
</code>
in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.openldap.org/software/man.cgi?query=ldap.conf&manpath=OpenLDAP+2.4-Release" rel="noopener noreferrer">
<span>
ldap.conf OpenLDAP 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>
for more complete instructions.
</p>
<p class="leafygreen-ui-1kp3ins">
For Windows deployment, you must add the LDAP server CA certificates to the
Windows certificate management tool. The exact name and functionality of the
tool may vary depending on operating system version. Please see the
documentation for your version of Windows for more information on
certificate management.
</p>
<p class="leafygreen-ui-1kp3ins">
Set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.transportSecurity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
transportSecurity
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
none
</code>
to disable TLS/SSL between
<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 the LDAP
server.
</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">
Setting
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.transportSecurity" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
transportSecurity
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
none
</code>
transmits plaintext information and possibly
credentials between
<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 the LDAP server.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.timeoutMS
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.timeoutMS" 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-setting-security.ldap.timeoutMS">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 10000
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The amount of time in milliseconds
<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>
should wait for an LDAP server
to respond to a request.
</p>
<p class="leafygreen-ui-1kp3ins">
Increasing the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.timeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
timeoutMS
</code>
</span>
</a>
may prevent connection failure between the
MongoDB server and the LDAP server, if the source of the failure is a
connection timeout. Decreasing the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.timeoutMS" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
timeoutMS
</code>
</span>
</a>
reduces the time
MongoDB waits for a response from the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.retryCount
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.retryCount" 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-setting-security.ldap.retryCount">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New in version 6.1
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
Number of operation retries by the server LDAP manager after a
network error.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setParameter/#mongodb-dbcommand-dbcmd.setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.userToDNMapping
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.userToDNMapping" 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-setting-security.ldap.userToDNMapping">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
Maps the username provided 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>
for authentication to a LDAP
Distinguished Name (DN). You may need to use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
to transform a
username into an LDAP DN in the following scenarios:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Performing LDAP authentication with simple LDAP binding, where users
authenticate to MongoDB with usernames that are not full LDAP DNs.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--ldapAuthzQueryTemplate">
<code class="leafygreen-ui-1l06pbn">
LDAP authorization query template
</code>
</a>
that requires a DN.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Transforming the usernames of clients authenticating to Mongo DB using
different authentication mechanisms (for example, x.509, kerberos) to a full LDAP
DN for authorization.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
expects a quote-enclosed JSON-string representing an ordered array
of documents. Each document contains a regular expression
<code class="leafygreen-ui-1l06pbn">
match
</code>
and
either a
<code class="leafygreen-ui-1l06pbn">
substitution
</code>
or
<code class="leafygreen-ui-1l06pbn">
ldapQuery
</code>
template used for transforming the
incoming username.
</p>
<p class="leafygreen-ui-1kp3ins">
Each document in the array has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n match: \"<regex>\"\n substitution: \"<ldap>\" | ldapQuery: \"<ldap>\"\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">match</span>: <span class="lg-highlight-string">"<regex>"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">substitution</span>: <span class="lg-highlight-string">"<LDAP DN>"</span> | <span class="lg-highlight-attr">ldapQuery</span>: <span class="lg-highlight-string">"<LDAP Query>"</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>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width: 10%;"/>
<col style="width: 70%;"/>
<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>
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>
Example
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
match
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
An ECMAScript-formatted regular expression (regex) to match against a
provided username. Each parenthesis-enclosed section represents a
regex capture group used by
<code class="leafygreen-ui-1l06pbn">
substitution
</code>
or
<code class="leafygreen-ui-1l06pbn">
ldapQuery
</code>
.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"(.+)ENGINEERING"
</code>
<code class="leafygreen-ui-1l06pbn">
"(.+)DBA"
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
substitution
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
An LDAP distinguished name (DN) formatting template that converts the
authentication name matched by the
<code class="leafygreen-ui-1l06pbn">
match
</code>
regex into a LDAP DN.
Each curly bracket-enclosed numeric value is replaced by the
corresponding
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.regular-expressions.info/refcapture.html" rel="noopener noreferrer">
<span>
regex capture group
</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>
extracted
from the authentication username through the
<code class="leafygreen-ui-1l06pbn">
match
</code>
regex.
</p>
<p class="leafygreen-ui-1kp3ins">
The result of the substitution must be an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.ietf.org/rfc/rfc4514.txt" rel="noopener noreferrer">
<span>
RFC4514
</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>
escaped string.
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"cn={0},ou=engineering,
dc=example,dc=com"
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ldapQuery
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A LDAP query formatting template that inserts the authentication
name matched by the
<code class="leafygreen-ui-1l06pbn">
match
</code>
regex into an LDAP query URI encoded
respecting RFC4515 and RFC4516. Each curly bracket-enclosed numeric
value is replaced by the corresponding
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.regular-expressions.info/refcapture.html" rel="noopener noreferrer">
<span>
regex capture group
</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>
extracted
from the authentication username through the
<code class="leafygreen-ui-1l06pbn">
match
</code>
expression.
<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>
executes the query against the LDAP server to retrieve
the LDAP DN for the authenticated user.
<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>
requires
exactly one returned result for the transformation to be
successful, or
<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>
skips this transformation.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"ou=engineering,dc=example,
dc=com??one?(user={0})"
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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 explanation of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.ietf.org/rfc/rfc4514.txt" rel="noopener noreferrer">
<span>
RFC4514
</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>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4515" rel="noopener noreferrer">
<span>
RFC4515
</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>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4516" rel="noopener noreferrer">
<span>
RFC4516
</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 LDAP queries is out
of scope for the MongoDB Documentation. Please review the RFC directly or
use your preferred LDAP resource.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For each document in the array, you must use either
<code class="leafygreen-ui-1l06pbn">
substitution
</code>
or
<code class="leafygreen-ui-1l06pbn">
ldapQuery
</code>
. You
<em>
cannot
</em>
specify both in the same document.
</p>
<p class="leafygreen-ui-1kp3ins">
When performing authentication or authorization,
<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>
steps through
each document in the array in the given order, checking the authentication
username against the
<code class="leafygreen-ui-1l06pbn">
match
</code>
filter. If a match is found,
<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>
applies the transformation and uses the output for
authenticating the user.
<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>
does not check the remaining documents
in the array.
</p>
<p class="leafygreen-ui-1kp3ins">
If the given document does not match the provided authentication
name,
<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>
continues
through the list of documents to find additional matches. If no
matches are found in any document, or the transformation the document
describes fails,
<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>
returns an error.
</p>
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
also returns an error if one
of the transformations cannot be evaluated due to networking or
authentication failures to the LDAP server.
<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>
rejects the connection request and does not
check the remaining documents in the array.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
accepts an empty string
<code class="leafygreen-ui-1l06pbn">
""
</code>
or empty array
<code class="leafygreen-ui-1l06pbn">
[ ]
</code>
in place of a
mapping document. If providing an empty string or empty array to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
, MongoDB maps the
authenticated username as the LDAP DN. Previously, providing an
empty mapping document would cause mapping to fail.
</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">
The following shows two transformation documents. The first
document matches against any string ending in
<code class="leafygreen-ui-1l06pbn">
@ENGINEERING
</code>
, placing
anything preceding the suffix into a regex capture group. The
second document matches against any string ending in
<code class="leafygreen-ui-1l06pbn">
@DBA
</code>
, placing
anything preceding the suffix into a regex capture group.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
You must pass the array to userToDNMapping as a string.
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"[\n {\n match: \"(.+)@ENGINEERING.EXAMPLE.COM\",\n substitution: \"cn={0},ou=engineering,dc=example,dc=com\"\n },\n {\n match: \"(.+)@DBA.EXAMPLE.COM\",\n ldapQuery: \"ou=dba,dc=example,dc=com??one?(user={0})\"\n\n }\n\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"> {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> match: "(.+)@ENGINEERING.EXAMPLE.COM",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> substitution: "cn={0},ou=engineering,dc=example,dc=com"</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"> match: "(.+)@DBA.EXAMPLE.COM",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ldapQuery: "ou=dba,dc=example,dc=com??one?(user={0})"</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"><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">
A user with username
<code class="leafygreen-ui-1l06pbn">
[email protected]
</code>
matches the first
document. The regex capture group
<code class="leafygreen-ui-1l06pbn">
{0}
</code>
corresponds to the string
<code class="leafygreen-ui-1l06pbn">
alice
</code>
. The resulting output is the DN
<code class="leafygreen-ui-1l06pbn">
"cn=alice,ou=engineering,dc=example,dc=com"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
A user with username
<code class="leafygreen-ui-1l06pbn">
[email protected]
</code>
matches the second document.
The regex capture group
<code class="leafygreen-ui-1l06pbn">
{0}
</code>
corresponds to the string
<code class="leafygreen-ui-1l06pbn">
bob
</code>
. The
resulting output is the LDAP query
<code class="leafygreen-ui-1l06pbn">
"ou=dba,dc=example,dc=com??one?(user=bob)"
</code>
.
<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>
executes this
query against the LDAP server, returning the result
<code class="leafygreen-ui-1l06pbn">
"cn=bob,ou=dba,dc=example,dc=com"
</code>
.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
is unset,
<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>
applies no transformations to the username
when attempting to authenticate or authorize a user against the LDAP server.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
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>
database command.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.authz.queryTemplate
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.authz.queryTemplate" 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-setting-security.ldap.authz.queryTemplate">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
A relative LDAP query URL formatted conforming to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4515" rel="noopener noreferrer">
<span>
RFC4515
</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>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4516" rel="noopener noreferrer">
<span>
RFC4516
</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>
that
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
executes to obtain
the LDAP groups to which the authenticated user belongs to. The query is
relative to the host or hosts specified in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.servers" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
security.ldap.servers
</code>
.
</span>
</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">
For better performance, consider placing the LDAP groups used for
MongoDB authorization into their own Organizational Unit (
<code class="leafygreen-ui-1l06pbn">
OU
</code>
).
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the URL, you can use the following substitution tokens:
</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>
Substitution Token
</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">
{USER}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Substitutes the authenticated username, or the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
transformed
</code>
</span>
</a>
username if a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
userToDNMapping
</code>
</span>
</a>
is specified.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{PROVIDED_USER}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Substitutes the supplied username, i.e. before either
authentication or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.userToDNMapping" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
LDAP transformation
</code>
.
</span>
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
When constructing the query URL, ensure that the order of LDAP parameters
respects RFC4516:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ dn [ ? [attributes] [ ? [scope] [ ? [filter] [ ? [Extensions] ] ] ] ] ]","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">[ dn [ ? [attributes] [ ? [scope] [ ? [filter] [ ? [Extensions] ] ] ] ] ]</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 your query includes an attribute,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
assumes that the query
retrieves a list of the DNs which this entity is a member of.
</p>
<p class="leafygreen-ui-1kp3ins">
If your query does not include an attribute,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
assumes
the query retrieves all entities which the user is member of.
</p>
<p class="leafygreen-ui-1kp3ins">
For each LDAP DN returned by the query,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
assigns the authorized
user a corresponding role on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database. If a role on the on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database exactly matches the DN,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
grants the user the
roles and privileges assigned to that role. See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createRole/#mongodb-method-db.createRole">
<code class="leafygreen-ui-1l06pbn">
db.createRole()
</code>
</a>
method for more information on creating roles.
</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">
This LDAP query returns any groups listed in the LDAP user object's
<code class="leafygreen-ui-1l06pbn">
memberOf
</code>
attribute.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"{USER}?memberOf?base\"","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-string">"{USER}?memberOf?base"</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">
Your LDAP configuration may not include the
<code class="leafygreen-ui-1l06pbn">
memberOf
</code>
attribute as part
of the user schema, may possess a different attribute for reporting group
membership, or may not track group membership through attributes.
Configure your query with respect to your own unique LDAP configuration.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If unset,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
cannot authorize users using LDAP.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting can be configured on 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>
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>
database command.
</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">
An explanation of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4515" rel="noopener noreferrer">
<span>
RFC4515
</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>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://tools.ietf.org/html/rfc4516" rel="noopener noreferrer">
<span>
RFC4516
</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 LDAP queries is out
of scope for the MongoDB Documentation. Please review the RFC directly or
use your preferred LDAP resource.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
security.ldap.validateLDAPServerConfig
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-security.ldap.validateLDAPServerConfig" 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-setting-security.ldap.validateLDAPServerConfig">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
A flag that determines if 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>
instance checks the availability of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-security.ldap.servers" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
LDAP server(s)
</code>
</span>
</a>
as part of its
startup:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance performs the availability check and only continues to
start up if the LDAP server is available.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instance skips the availability check; i.e. the instance starts up
even if the LDAP server is unavailable.
</p>
</li>
</ul>
</dd>
</dl>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
Option
<a class="headerlink leafygreen-ui-1kepx47" href="#setparameter-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="setparameter-option">
</div>
</a>
</h3>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-setParameter" 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-setting-setParameter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Set MongoDB parameter or parameters described in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/">
MongoDB Server Parameters for a Self-Managed Deployment
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To set parameters in the YAML configuration file, use the following
format:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n <parameter1>: <value1>\n <parameter2>: <value2>","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-string"><parameter1>:</span> <span class="lg-highlight-string"><value1></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string"><parameter2>:</span> <span class="lg-highlight-string"><value2></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 example, to specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.enableLocalhostAuthBypass">
<code class="leafygreen-ui-1l06pbn">
enableLocalhostAuthBypass
</code>
</a>
in
the configuration file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n enableLocalhostAuthBypass: false","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">enableLocalhostAuthBypass:</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>
</dd>
</dl>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
LDAP Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#ldap-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="ldap-parameters">
</div>
</a>
</h4>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
setParameter.ldapUserCacheInvalidationInterval
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-setParameter.ldapUserCacheInvalidationInterval" 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-setting-setParameter.ldapUserCacheInvalidationInterval">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 30
</p>
<p class="leafygreen-ui-1kp3ins">
For use with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
servers using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-ldap-external/#std-label-security-ldap-external">
LDAP Authorization on Self-Managed Deployments.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The interval (in seconds)
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
waits
between external user cache flushes. After
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
flushes the external
user cache, MongoDB
reacquires authorization data from the LDAP server the
next time an LDAP-authorized user issues an operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Increasing the value specified increases the amount of time
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and the LDAP server can be out of sync, but reduces the load on
the LDAP server. Conversely, decreasing the value specified
decreases the time
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
and the LDAP server can be out of sync while
increasing the load on the LDAP server.
</p>
</dd>
</dl>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"setParameter:\n ldapUserCacheInvalidationInterval: <int>","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">ldapUserCacheInvalidationInterval:</span> <span class="lg-highlight-string"><int></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">
<code class="leafygreen-ui-1l06pbn">
storage
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#storage-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="storage-options">
</div>
</a>
</h3>
<div>
<p>
<em>
Changed in version 6.1
</em>
:
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB always enables journaling. As a result, MongoDB removes the
<code class="leafygreen-ui-1l06pbn">
storage.journal.enabled
</code>
option and the corresponding
<code class="leafygreen-ui-1l06pbn">
--journal
</code>
and
<code class="leafygreen-ui-1l06pbn">
--nojournal
</code>
command-line options.
</p>
</li>
</ul>
</p>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n dbPath: <string>\n journal:\n commitIntervalMs: <num>\n directoryPerDB: <boolean>\n syncPeriodSecs: <int>\n engine: <string>\n wiredTiger:\n engineConfig:\n cacheSizeGB: <number>\n journalCompressor: <string>\n directoryForIndexes: <boolean>\n maxCacheOverflowFileSizeGB: <number>\n collectionConfig:\n blockCompressor: <string>\n indexConfig:\n prefixCompression: <boolean>\n inMemory:\n engineConfig:\n inMemorySizeGB: <number>\n oplogMinRetentionHours: <double>","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">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dbPath:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">journal:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">commitIntervalMs:</span> <span class="lg-highlight-string"><num></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">directoryPerDB:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">syncPeriodSecs:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">engine:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wiredTiger:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">engineConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cacheSizeGB:</span> <span class="lg-highlight-string"><number></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">journalCompressor:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">directoryForIndexes:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxCacheOverflowFileSizeGB:</span> <span class="lg-highlight-string"><number></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collectionConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">blockCompressor:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">indexConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">prefixCompression:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">inMemory:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">engineConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">inMemorySizeGB:</span> <span class="lg-highlight-string"><number></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">oplogMinRetentionHours:</span> <span class="lg-highlight-string"><double></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.dbPath" 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-setting-storage.dbPath">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
/data/db
</code>
on Linux and macOS
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
\data\db
</code>
on Windows
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The directory where 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 stores its
data.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
setting is available only for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Configuration Files
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The default
<code class="leafygreen-ui-1l06pbn">
mongod.conf
</code>
configuration file included with
package manager installations uses the following platform-specific
default values for
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width: 35%;"/>
<col style="width: 30%;"/>
<col style="width: 35%;"/>
</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>
Platform
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Package Manager
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Default
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-vm4wms" tabindex="0">
RHEL
</span>
/ CentOS and Amazon
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
yum
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
/var/lib/mongo
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
SUSE
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zypper
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
/var/lib/mongo
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Ubuntu and Debian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
apt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
/var/lib/mongodb
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
macOS
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
brew
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
/usr/local/var/mongodb
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The Linux package init scripts do not expect
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
to change from the
defaults. If you use the Linux packages and change
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
, you must
use your own init scripts and disable the built-in scripts.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.journal.commitIntervalMs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.journal.commitIntervalMs" 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-setting-storage.journal.commitIntervalMs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: number
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 100
</p>
<p class="leafygreen-ui-1kp3ins">
The maximum amount of time in milliseconds that
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 allows between
journal operations. Values can range from 1 to 500 milliseconds. Lower
values increase the durability of the journal, at the expense of disk
performance.
</p>
<p class="leafygreen-ui-1kp3ins">
On WiredTiger, the default journal commit interval is 100
milliseconds. Additionally, a write that includes or implies
<code class="leafygreen-ui-1l06pbn">
j:true
</code>
causes an immediate sync of the journal. For details
or additional conditions that affect the frequency of the sync, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journal-process">
Journaling Process.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.journal.commitIntervalMs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.journal.commitIntervalMs
</code>
</span>
</a>
setting is available only for
<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">
Not available for
<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 use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.directoryPerDB" 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-setting-storage.directoryPerDB">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
true
</code>
, MongoDB uses a separate directory to store data for each database. The
directories are under the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
directory, and each subdirectory
name corresponds to the database name.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.directoryPerDB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
</span>
</a>
setting is available only for
<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">
Not available for
<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 use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, dropping the final collection in a database
(or dropping the database itself) when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.directoryPerDB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
</span>
</a>
is enabled deletes the newly empty
subdirectory for that database.
</p>
<p class="leafygreen-ui-1kp3ins">
To change the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.directoryPerDB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
</span>
</a>
option for existing
deployments:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For standalone instances:
</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/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongodump
</code>
</span>
</a>
on the existing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance to generate a backup.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Stop 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">
Add the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.directoryPerDB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
</span>
</a>
value
<strong>
and
</strong>
configure a new data directory
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
instance.
</p>
</li>
<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/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongorestore
</code>
</span>
</a>
to populate the new data
directory.
</p>
</li>
</ol>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For replica sets:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Stop a secondary member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.directoryPerDB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.directoryPerDB
</code>
</span>
</a>
value
<strong>
and
</strong>
configure a new data directory to that secondary member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restart that secondary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-sync/#std-label-replica-set-initial-sync">
initial sync
</a>
to populate
the new data directory.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Update remaining secondaries in the same fashion.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Step down the primary, and update the stepped-down member in the
same fashion.
</p>
</li>
</ol>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.syncPeriodSecs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.syncPeriodSecs" 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-setting-storage.syncPeriodSecs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: number
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 60
</p>
<p class="leafygreen-ui-1kp3ins">
The amount of time that can pass before MongoDB flushes data to the data
files.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Do not set this value on
production systems.
</strong>
In almost every situation, you should use the
default setting.
</p>
<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>
process writes data very quickly to the journal and
lazily to the data files.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.syncPeriodSecs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.syncPeriodSecs
</code>
</span>
</a>
has no effect on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/journaling/#std-label-journaling-internals">
Journaling
</a>
, but if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.syncPeriodSecs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.syncPeriodSecs
</code>
</span>
</a>
is
set to
<code class="leafygreen-ui-1l06pbn">
0
</code>
the journal eventually consumes all available disk space.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.syncPeriodSecs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.syncPeriodSecs
</code>
</span>
</a>
setting is available only for
<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">
Not available for
<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 use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine.
</a>
</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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.engine
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.engine" 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-setting-storage.engine">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
wiredTiger
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
The storage engine for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
database. Available
values include:
</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>
Value
</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">
wiredTiger
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
To specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/">
WiredTiger Storage Engine.
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
inMemory
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
To specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/">
In-Memory Storage Engine for Self-Managed Deployments.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Available in MongoDB Enterprise only.
</p>
<p class="leafygreen-ui-1kp3ins">
If you attempt to start a
<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
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
that contains data files produced
by a storage engine other than the one specified by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.engine" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.engine
</code>
</span>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
refuses to start.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.oplogMinRetentionHours
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.oplogMinRetentionHours" 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-setting-storage.oplogMinRetentionHours">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: double
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the minimum number of hours to preserve an oplog entry,
where the decimal values represent the fractions of an hour. For
example, a value of
<code class="leafygreen-ui-1l06pbn">
1.5
</code>
represents one hour and thirty
minutes.
</p>
<p class="leafygreen-ui-1kp3ins">
The value must be greater than or equal to
<code class="leafygreen-ui-1l06pbn">
0
</code>
. A value of
<code class="leafygreen-ui-1l06pbn">
0
</code>
indicates that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
should truncate the oplog
starting with the oldest entries to maintain the configured
maximum oplog size.
</p>
<p class="leafygreen-ui-1kp3ins">
Defaults to
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</p>
<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>
started with
<code class="leafygreen-ui-1l06pbn">
oplogMinRetentionHours
</code>
only
removes an oplog entry
<em>
if
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog has reached the maximum configured oplog size
<em>
and
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog entry is older than the configured number of hours based
on the host system clock.
</p>
</li>
</ul>
<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>
has the following behavior when configured
with a minimum oplog retention period:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog can grow without constraint so as to retain oplog entries
for the configured number of hours. This may result in reduction or
exhaustion of system disk space due to a combination of high write
volume and large retention period.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the oplog grows beyond its maximum size, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
may continue to hold that disk space even if the oplog returns to its
maximum size
<em>
or
</em>
is configured for a smaller maximum size. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#std-label-replSetResizeOplog-cmd-compact">
Reducing Oplog Size Does Not Immediately Return Disk Space.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
compares the system wall clock to an
oplog entries creation wall clock time when enforcing oplog entry
retention. Clock drift between cluster components may result in
unexpected oplog retention behavior. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-production-notes-clock-synchronization">
Clock Synchronization
</a>
for more information on
clock synchronization across cluster members.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To change the minimum oplog retention period after 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>
, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
enables you to resize the oplog
dynamically without restarting 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. To
persist the changes made using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
through a restart, update the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.oplogMinRetentionHours" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
oplogMinRetentionHours
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wiredTiger-storage-options">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#storage.wiredtiger-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="storage.wiredtiger-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n wiredTiger:\n engineConfig:\n cacheSizeGB: <number>\n journalCompressor: <string>\n directoryForIndexes: <boolean>\n maxCacheOverflowFileSizeGB: <number>\n collectionConfig:\n blockCompressor: <string>\n indexConfig:\n prefixCompression: <boolean>","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">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wiredTiger:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">engineConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cacheSizeGB:</span> <span class="lg-highlight-string"><number></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">journalCompressor:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">directoryForIndexes:</span> <span class="lg-highlight-string"><boolean></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">maxCacheOverflowFileSizeGB:</span> <span class="lg-highlight-string"><number></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">collectionConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">blockCompressor:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">indexConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">prefixCompression:</span> <span class="lg-highlight-string"><boolean></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.cacheSizeGB
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB" 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-setting-storage.wiredTiger.engineConfig.cacheSizeGB">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: float
</p>
<p class="leafygreen-ui-1kp3ins">
Defines the maximum size of the internal cache that WiredTiger
uses for all data. The memory consumed by an index build (see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxIndexBuildMemoryUsageMegabytes">
<code class="leafygreen-ui-1l06pbn">
maxIndexBuildMemoryUsageMegabytes
</code>
</a>
) is separate from the
WiredTiger cache memory.
</p>
<p class="leafygreen-ui-1kp3ins">
Values can range from
<code class="leafygreen-ui-1l06pbn">
0.25
</code>
GB to
<code class="leafygreen-ui-1l06pbn">
10000
</code>
GB.
</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">
Avoid increasing the WiredTiger internal cache size above its
default value.
</p>
<p class="leafygreen-ui-1kp3ins">
With WiredTiger, MongoDB utilizes both the WiredTiger internal cache
and the filesystem cache.
</p>
<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>
<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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.cacheSizeGB
</code>
</span>
</a>
limits the size of the WiredTiger internal
cache. The operating system uses the available free memory
for filesystem cache, which allows the compressed MongoDB data
files to stay in memory. In addition, the operating system
uses any free RAM to buffer file system blocks and file system
cache.
</p>
<p class="leafygreen-ui-1kp3ins">
To accommodate the additional consumers of RAM, you may have to
decrease WiredTiger internal cache size.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The default WiredTiger internal cache size value assumes that there is a
single
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance per machine. If a single machine
contains multiple MongoDB instances, then you should decrease the setting to
accommodate the other
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances.
</p>
<p class="leafygreen-ui-1kp3ins">
If you run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
in a container (for example,
<code class="leafygreen-ui-1l06pbn">
lxc
</code>
,
<code class="leafygreen-ui-1l06pbn">
cgroups
</code>
, Docker, etc.) that does
<em>
not
</em>
have access to all of the
RAM available in a system, you must set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.engineConfig.cacheSizeGB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.cacheSizeGB
</code>
</span>
</a>
to a value
less than the amount of RAM available in the container. The exact
amount depends on the other processes running in the container. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hostInfo/#mongodb-data-hostInfo.system.memLimitMB">
<code class="leafygreen-ui-1l06pbn">
memLimitMB
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.journalCompressor
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.engineConfig.journalCompressor" 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-setting-storage.wiredTiger.engineConfig.journalCompressor">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: snappy
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the type of compression to use to compress WiredTiger
journal data.
</p>
<p class="leafygreen-ui-1kp3ins">
Available compressors are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
none
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-snappy">
snappy
</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-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>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.directoryForIndexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.engineConfig.directoryForIndexes" 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-setting-storage.wiredTiger.engineConfig.directoryForIndexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.engineConfig.directoryForIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.directoryForIndexes
</code>
</span>
</a>
is
<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>
stores indexes and collections in separate
subdirectories under the data (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.dbPath" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</span>
</a>
) directory.
Specifically,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
stores the indexes in a subdirectory named
<code class="leafygreen-ui-1l06pbn">
index
</code>
and the collection data in a subdirectory named
<code class="leafygreen-ui-1l06pbn">
collection
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
By using a symbolic link, you can specify a different location for
the indexes. Specifically, when
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance is
<strong>
not
</strong>
running, move the
<code class="leafygreen-ui-1l06pbn">
index
</code>
subdirectory to the destination and
create a symbolic link named
<code class="leafygreen-ui-1l06pbn">
index
</code>
under the data directory to
the new destination.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.engineConfig.zstdCompressionLevel
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.engineConfig.zstdCompressionLevel" 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-setting-storage.wiredTiger.engineConfig.zstdCompressionLevel">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 6
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the level of compression applied when using
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zstd">
zstd
</a>
compressor.
</p>
<p class="leafygreen-ui-1kp3ins">
Values can range from 1 to 22.
</p>
<p class="leafygreen-ui-1kp3ins">
The higher the specified value for
<code class="leafygreen-ui-1l06pbn">
zstdCompressionLevel
</code>
the higher the compression which is applied.
</p>
<p class="leafygreen-ui-1kp3ins">
Only applicable when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.collectionConfig.blockCompressor" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
blockCompressor
</code>
</span>
</a>
is set to
<code class="leafygreen-ui-1l06pbn">
zstd
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Available starting in MongoDB 5.0
</em>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.collectionConfig.blockCompressor
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.collectionConfig.blockCompressor" 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-setting-storage.wiredTiger.collectionConfig.blockCompressor">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: snappy
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies the default compression for collection data. You can
override this on a per-collection basis when creating collections.
</p>
<p class="leafygreen-ui-1kp3ins">
Available compressors are:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
none
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-snappy">
snappy
</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-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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.collectionConfig.blockCompressor" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.collectionConfig.blockCompressor
</code>
</span>
</a>
affects all collections created. If you change
the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.collectionConfig.blockCompressor" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.collectionConfig.blockCompressor
</code>
</span>
</a>
on an existing MongoDB deployment, all new
collections uses the specified compressor. Existing collections
continue to use the compressor specified when they were
created, or the default compressor at that time.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.indexConfig.prefixCompression
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.wiredTiger.indexConfig.prefixCompression" 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-setting-storage.wiredTiger.indexConfig.prefixCompression">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
Enables or disables
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-prefix-compression">
prefix compression
</a>
for index data.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
true
</code>
for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.indexConfig.prefixCompression" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.indexConfig.prefixCompression
</code>
</span>
</a>
to enable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-prefix-compression">
prefix compression
</a>
for
index data, or
<code class="leafygreen-ui-1l06pbn">
false
</code>
to disable prefix compression for index data.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.indexConfig.prefixCompression" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.indexConfig.prefixCompression
</code>
</span>
</a>
setting affects all indexes created. If you change
the value of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-storage.wiredTiger.indexConfig.prefixCompression" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
storage.wiredTiger.indexConfig.prefixCompression
</code>
</span>
</a>
on an existing MongoDB deployment, all new
indexes uses prefix compression. Existing indexes
are not affected.
</p>
</dd>
</dl>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
storage.inmemory
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#storage.inmemory-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="storage.inmemory-options">
</div>
</a>
</h4>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"storage:\n inMemory:\n engineConfig:\n inMemorySizeGB: <number>","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">storage:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">inMemory:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">engineConfig:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">inMemorySizeGB:</span> <span class="lg-highlight-string"><number></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
storage.inMemory.engineConfig.inMemorySizeGB
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-storage.inMemory.engineConfig.inMemorySizeGB" 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-setting-storage.inMemory.engineConfig.inMemorySizeGB">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: float
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 50% of physical RAM less 1 GB
</p>
<p class="leafygreen-ui-1kp3ins">
Values can range from 256MB to 10TB and can be a float.
</p>
<p class="leafygreen-ui-1kp3ins">
Maximum amount of memory to allocate for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/">
in-memory storage
engine
</a>
data, including indexes, oplog if 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 part of replica set, replica set or sharded
cluster metadata, etc.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, the in-memory storage engine uses 50% of physical RAM minus
1 GB.
</p>
<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>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-operation-profiling-configuration-options">
</span>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
operationProfiling
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#operationprofiling-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="operationprofiling-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"operationProfiling:\n mode: <string>\n slowOpThresholdMs: <int>\n slowOpSampleRate: <double>\n filter: <string>","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">operationProfiling:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">slowOpThresholdMs:</span> <span class="lg-highlight-string"><int></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">slowOpSampleRate:</span> <span class="lg-highlight-string"><double></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter:</span> <span class="lg-highlight-string"><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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-configuration-profiling-mode">
</span>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
operationProfiling.mode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-operationProfiling.mode" 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-setting-operationProfiling.mode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
off
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies which operations should be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
profiled
</a>
.
The following profiler levels are available:
</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>
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">
off
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The profiler is off and does not collect any data.
This is the default profiler level.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
slowOp
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The profiler collects data for operations that take longer
than the value of
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
all
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The profiler collects data for all operations.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Profiling can degrade performance and expose unencrypted query data in the
system log. Carefully consider any performance and security implications
before configuring and enabling the profiler on a production deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/#std-label-database-profiling-overhead">
Profiler Overhead
</a>
for more information on
potential performance degradation.
</p>
</div>
</div>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-configuration-profiling-slowOpThresholdMs">
</span>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
operationProfiling.slowOpThresholdMs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-operationProfiling.slowOpThresholdMs" 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-setting-operationProfiling.slowOpThresholdMs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 100
</p>
<p class="leafygreen-ui-1kp3ins">
The slow operation time threshold, in milliseconds. Operations that run
for longer than this threshold are considered
<em>
slow
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Slow operations are logged based on
<code class="leafygreen-ui-1l06pbn">
workingMillis
</code>
, which is the
amount of time that MongoDB spends working on that operation. This means
that factors such as waiting for locks and flow control do not affect
whether an operation exceeds the slow operation threshold.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
is set to
<code class="leafygreen-ui-1l06pbn">
0
</code>
, MongoDB records
<em>
slow
</em>
operations to the diagnostic log at a rate determined by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-operationProfiling.slowOpSampleRate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
At higher
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
settings, all operations appear in
the diagnostic log regardless of their latency with the following
exception: the logging of slow oplog entry messages by the
secondaries. The secondaries log only the slow oplog
entries; increasing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
does not log all
oplog entries.
</p>
<p class="leafygreen-ui-1kp3ins">
This setting is available for
<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>
</p>
<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/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances, the setting affects both
the diagnostic log and, if enabled, the profiler.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the setting affects the
diagnostic log only and not the profiler, since profiling is not
available on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</a>
</p>
</li>
</ul>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-configuration-profiling-slowOpSampleRate">
</span>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
operationProfiling.slowOpSampleRate
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-operationProfiling.slowOpSampleRate" 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-setting-operationProfiling.slowOpSampleRate">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: double
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 1.0
</p>
<p class="leafygreen-ui-1kp3ins">
The fraction of
<em>
slow
</em>
operations that should be profiled or logged.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-operationProfiling.slowOpSampleRate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
operationProfiling.slowOpSampleRate
</code>
</span>
</a>
accepts values between
0 and 1, inclusive.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-operationProfiling.slowOpSampleRate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
</span>
</a>
setting is
available for
<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>
</p>
<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/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instances, the setting affects both
the diagnostic log and, if enabled, the profiler.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the setting affects the
diagnostic log only and not the profiler since profiling is not
available on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
.
</a>
</p>
</li>
</ul>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
operationProfiling.filter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-operationProfiling.filter" 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-setting-operationProfiling.filter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string representation of a query document
</p>
<p class="leafygreen-ui-1kp3ins">
A filter expression that controls which operations are profiled and
logged.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
filter
</code>
is set,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-operationProfiling.slowOpThresholdMs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
slowOpThresholdMs
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-operationProfiling.slowOpSampleRate" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
</span>
</a>
are not used for
profiling and slow-query log lines.
</p>
<p class="leafygreen-ui-1kp3ins">
When you set a profile filter in the configuration file, the filter
applies to all databases in the deployment. To set a profile filter
for a specific database, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.setProfilingLevel/#mongodb-method-db.setProfilingLevel">
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</a>
method.
</p>
<p class="leafygreen-ui-1kp3ins">
The option takes a string representation of a query document
of the form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ <field1>: <expression1>, ... }","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">{ <field1>: <expression1>, ... }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
<field>
</code>
can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
any field in the profiler output
</a>
. The
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors">
query condition
expression.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To specify a profiling filter in a
<a aria-current="page" class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
</a>
, you must:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Enclose the filter document in single quotes to pass the document
as a string.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the YAML format of the configuration file.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For example, the following
<code class="leafygreen-ui-1l06pbn">
filter
</code>
configures the profiler to
log
<code class="leafygreen-ui-1l06pbn">
query
</code>
operations that take longer than 2 seconds:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"operationProfiling:\n mode: all\n filter: '{ op: \"query\", millis: { $gt: 2000 } }'","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">operationProfiling:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">mode:</span> <span class="lg-highlight-string">all</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter:</span> <span class="lg-highlight-string">'{ op: "query", millis: { $gt: 2000 } }'</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replication-options">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
replication
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#replication-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="replication-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"replication:\n oplogSizeMB: <int>\n replSetName: <string>\n enableMajorityReadConcern: <boolean>","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">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">oplogSizeMB:</span> <span class="lg-highlight-string"><int></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">enableMajorityReadConcern:</span> <span class="lg-highlight-string"><boolean></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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
replication.oplogSizeMB
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-replication.oplogSizeMB" 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-setting-replication.oplogSizeMB">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
The maximum size in megabytes for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
. The
<code class="leafygreen-ui-1l06pbn">
oplogSizeMB
</code>
setting configures the uncompressed size of the
oplog, not the size on disk.
</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 oplog can grow past its configured size
limit to avoid deleting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
<code class="leafygreen-ui-1l06pbn">
majority commit point
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
By default, 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 creates an oplog based
on the maximum amount of space available. For 64-bit systems, the
oplog is typically 5% of available disk space.
</p>
<p class="leafygreen-ui-1kp3ins">
Once the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
has created the oplog for the first
time, changing the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.oplogSizeMB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.oplogSizeMB
</code>
</span>
</a>
option does not
affect the size of the oplog. To change the maximum oplog size after
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>
, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
enables you to resize the oplog dynamically without restarting 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. To persist the changes made using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
through a restart, update the value
of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.oplogSizeMB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
oplogSizeMB
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-replica-set-oplog-sizing">
Oplog Size
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.oplogSizeMB" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.oplogSizeMB
</code>
</span>
</a>
setting is available only for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-replication.replSetName" 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-setting-replication.replSetName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The name of the replica set that 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 part of. All hosts
in the replica set must have the same set name.
</p>
<p class="leafygreen-ui-1kp3ins">
If your application connects to more than one replica set, each set must
have a distinct name. Some drivers group replica set connections by
replica set name.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.replSetName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</span>
</a>
setting is available only for
<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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.replSetName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</span>
</a>
cannot be used in conjunction with
<code class="leafygreen-ui-1l06pbn">
storage.indexBuildRetry
</code>
.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
replication.enableMajorityReadConcern
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-replication.enableMajorityReadConcern" 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-setting-replication.enableMajorityReadConcern">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
Configures support for
<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.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.enableMajorityReadConcern" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
enableMajorityReadConcern
</code>
</span>
</a>
cannot be changed
and is always set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
. Attempting to start a storage engine
that does not support majority read concern with the
<code class="leafygreen-ui-1l06pbn">
--enableMajorityReadConcern
</code>
option fails and return an error
message.
</p>
<p class="leafygreen-ui-1kp3ins">
In earlier versions of MongoDB,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.enableMajorityReadConcern" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
enableMajorityReadConcern
</code>
</span>
</a>
was configurable.
</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 you are using a three-member primary-secondary-arbiter (PSA)
architecture, consider the following:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The 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>
can cause
performance issues if a secondary is unavailable or lagging. For
advice on how to mitigate these issues, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/mitigate-psa-performance-issues/#std-label-performance-issues-psa">
Mitigate Performance Issues with a Self-Managed PSA Replica Set.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you are using a global default
<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 the write concern is less than the size of the majority,
your queries may return stale (not fully replicated) data.
</p>
</li>
</ul>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
sharding
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#sharding-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="sharding-options">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n clusterRole: <string>","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"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-sharding.clusterRole" 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-setting-sharding.clusterRole">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The role that 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 has in the sharded
cluster. Set this setting to one of the following:
</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>
Value
</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">
configsvr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Start this instance as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-server">
config server
</a>
. The instance
starts on port
<code class="leafygreen-ui-1l06pbn">
27019
</code>
by default.
</p>
<p class="leafygreen-ui-1kp3ins">
When you configure a MongoDB instance as
clusterRole
<code class="leafygreen-ui-1l06pbn">
configsvr
</code>
you must also specify a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.replSetName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetName
</code>
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
shardsvr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Start this instance as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
. The instance starts
on port
<code class="leafygreen-ui-1l06pbn">
27018
</code>
by default.
</p>
<p class="leafygreen-ui-1kp3ins">
When you configure a MongoDB instance as a
a clusterRole
<code class="leafygreen-ui-1l06pbn">
shardsvr
</code>
you must also specify a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.replSetName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetName
</code>
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Setting
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole
</code>
requires 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 to be running with replication. To deploy the instance as
a replica set member, use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.replSetName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetName
</code>
</span>
</a>
setting and specify the name of the replica set.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-sharding.clusterRole" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sharding.clusterRole
</code>
</span>
</a>
setting is available only for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
.
</a>
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
sharding.archiveMovedChunks
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-sharding.archiveMovedChunks" 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-setting-sharding.archiveMovedChunks">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false.
</p>
<p class="leafygreen-ui-1kp3ins">
During chunk migration, a shard does not save documents migrated from
the shard.
</p>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
auditLog
</code>
Options
<a class="headerlink leafygreen-ui-1kepx47" href="#auditlog-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="auditlog-options">
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self">
<span>
MongoDB Atlas
</span>
</a>
.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"auditLog:\n destination: <string>\n format: <string>\n path: <string>\n filter: <string>\n schema: <string>","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">auditLog:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">destination:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">path:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">schema:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.auditEncryptionKeyIdentifier" 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-setting-auditLog.auditEncryptionKeyIdentifier">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 6.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies the unique identifier of the Key Management
Interoperability Protocol (KMIP) key for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log">
audit log encryption.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.auditEncryptionKeyIdentifier" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.localAuditKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</span>
</a>
together.
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
.
MongoDB Enterprise and Atlas have different configuration
requirements.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.compressionMode
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.compressionMode" 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-setting-auditLog.compressionMode">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies the compression mode for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log">
audit log encryption
</a>
. You must also enable audit log
encryption using either
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.auditEncryptionKeyIdentifier" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</span>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.localAuditKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.compressionMode" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.compressionMode
</code>
</span>
</a>
can be set to one of these values:
</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>
Value
</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">
zstd
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zstd">
zstd
</a>
algorithm to compress the audit log.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
none
</code>
<em>
(default)
</em>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Do not compress the audit log.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
.
MongoDB Enterprise and Atlas have different configuration
requirements.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.destination
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.destination" 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-setting-auditLog.destination">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
When set,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.destination
</code>
</span>
</a>
enables
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
auditing
</a>
and
specifies where
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
sends all audit events.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.destination
</code>
</span>
</a>
can have one of the following values:
</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>
Value
</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">
syslog
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Output the audit events to syslog in JSON format. Not available on
Windows. Audit messages have a syslog severity level of
<code class="leafygreen-ui-1l06pbn">
info
</code>
and a facility level of
<code class="leafygreen-ui-1l06pbn">
user
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The syslog message limit can result in the truncation of
audit messages. The auditing system neither detects the
truncation nor errors upon its occurrence.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
console
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Output the audit events to
<code class="leafygreen-ui-1l06pbn">
stdout
</code>
in JSON format.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
file
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Output the audit events to the file specified in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.path
</code>
</span>
</a>
in the format specified in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.format" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.format
</code>
.
</span>
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self">
<span>
MongoDB Atlas
</span>
</a>
.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.filter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.filter" 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-setting-auditLog.filter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string representation of a document
</p>
<p class="leafygreen-ui-1kp3ins">
The filter to limit the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-audit-action-details-results">
types of operations
</a>
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/">
audit system
</a>
records. The option takes a string representation
of a query document of the form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ <field1>: <expression1>, ... }","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">{ <field1>: <expression1>, ... }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
<field>
</code>
can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/">
any field in the audit message
</a>
, including fields returned in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-audit-action-details-results">
param
</a>
document. The
<code class="leafygreen-ui-1l06pbn">
<expression>
</code>
is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors">
query condition expression.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To specify an audit filter, enclose the filter document in single
quotes to pass the document as a string.
</p>
<p class="leafygreen-ui-1kp3ins">
To specify the audit filter in a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-configuration-options" target="_self">
<span>
configuration file
</span>
</a>
, you must use the YAML format
of the configuration file.
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self">
<span>
MongoDB Atlas
</span>
</a>
.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.format
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.format" 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-setting-auditLog.format">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The format of the output file for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/">
auditing
</a>
if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
destination
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
file
</code>
. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.format" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.format
</code>
</span>
</a>
option can have one of the following values:
</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>
Value
</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">
JSON
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Output the audit events in JSON format to the file specified
in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.path
</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">
BSON
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Output the audit events in BSON binary format to the file
specified in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.path
</code>
.
</span>
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Printing audit events to a file in JSON format degrades server
performance more than printing to a file in BSON format.
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://cloud.mongodb.com/user#/atlas/login" target="_self">
<span>
MongoDB Atlas
</span>
</a>
.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.localAuditKeyFile" 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-setting-auditLog.localAuditKeyFile">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<div>
<p>
<em>
New in version 5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies the path and file name for a local audit key file for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log">
audit log encryption.
</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">
Only use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.localAuditKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</span>
</a>
for testing because the key is
not secured. To secure the key, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.auditEncryptionKeyIdentifier" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</span>
</a>
and an external Key
Management Interoperability Protocol (KMIP) server.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You cannot use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.localAuditKeyFile" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.auditEncryptionKeyIdentifier" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.auditEncryptionKeyIdentifier
</code>
</span>
</a>
together.
</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">
Available only in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise
</span>
</a>
.
MongoDB Enterprise and Atlas have different configuration
requirements.
</p>
</div>
</div>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.path
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.path" 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-setting-auditLog.path">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The output file for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
auditing
</a>
if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.destination" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
destination
</code>
</span>
</a>
has value of
<code class="leafygreen-ui-1l06pbn">
file
</code>
. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-auditLog.path" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
auditLog.path
</code>
</span>
</a>
option can take either a full path name or a relative path name.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.runtimeConfiguration
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.runtimeConfiguration" 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-setting-auditLog.runtimeConfiguration">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies if a node allows runtime configuration of audit filters
and the auditAuthorizationSuccess variable. If
<code class="leafygreen-ui-1l06pbn">
true
</code>
the node
can take part in Online Audit Filter Management.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
auditLog.schema
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-auditLog.schema" 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-setting-auditLog.schema">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
:
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
</p>
<div>
<p>
<em>
New in version 8.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Specifies the format used for audit logs. You can specify one of the
following values for
<code class="leafygreen-ui-1l06pbn">
auditLog.schema
</code>
:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width: 10%;"/>
<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>
Value
</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">
mongo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Logs are written in a format designed by MongoDB.
</p>
<p class="leafygreen-ui-1kp3ins">
For example log messages, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/mongo/#std-label-event-audit-messages-mongo">
mongo Schema Audit Messages.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
OCSF
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Logs are written in
<span class="leafygreen-ui-vm4wms" tabindex="0">
OCSF
</span>
format. This option provides logs in a standardized
format compatible with log processors.
</p>
<p class="leafygreen-ui-1kp3ins">
For example log messages, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/audit-message/ocsf/#std-label-event-audit-messages-ocsf">
OCSF Schema Audit Messages.
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
-only Options
<a class="headerlink leafygreen-ui-1kepx47" href="#mongos-only-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="mongos-only-options">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"replication:\n localPingThresholdMs: <int>\n\nsharding:\n configDB: <string>","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">replication:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">localPingThresholdMs:</span> <span class="lg-highlight-string"><int></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-attr">sharding:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configDB:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
replication.localPingThresholdMs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-replication.localPingThresholdMs" 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-setting-replication.localPingThresholdMs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 15
</p>
<p class="leafygreen-ui-1kp3ins">
The ping time, in milliseconds, that
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
uses
to determine which secondary replica set members to pass read
operations from clients. The default value of
<code class="leafygreen-ui-1l06pbn">
15
</code>
corresponds to
the default value in all of the client
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
drivers.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
receives a request that permits reads to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members, 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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Finds the member of the set with the lowest ping time.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Constructs a list of replica set members that is within a ping time of
15 milliseconds of the nearest suitable member of the set.
</p>
<p class="leafygreen-ui-1kp3ins">
If you specify a value for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.localPingThresholdMs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.localPingThresholdMs
</code>
</span>
</a>
option,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
construct the list of replica members that are
within the latency allowed by this value.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Selects a member to read from at random from this list.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The ping time used for a member compared by the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-replication.localPingThresholdMs" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replication.localPingThresholdMs
</code>
</span>
</a>
setting is a
moving average of recent ping times, calculated at most every 10
seconds. As a result, some queries may reach members above the threshold
until the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
recalculates the average.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-mechanics/#std-label-replica-set-read-preference-behavior-member-selection">
Read Preference for Replica Sets
</a>
section of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
read preference
</a>
documentation for more information.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
sharding.configDB
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-sharding.configDB" 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-setting-sharding.configDB">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server">
configuration servers
</a>
for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Config servers for sharded clusters are
deployed as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/">
replica set
</a>
. The
replica set config servers must run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/">
WiredTiger storage engine.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the config server replica set name and the hostname and port of
at least one of the members of the config server replica set.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sharding:\n configDB: <configreplsetname>/cfg1.example.net:27019, cfg2.example.net:27019,...","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">sharding</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">configDB</span>: <configReplSetName>/cfg1.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-property">net</span>:<span class="lg-highlight-number">27019</span>, cfg2.<span class="lg-highlight-property">example</span>.<span class="lg-highlight-property">net</span>:<span class="lg-highlight-number">27019</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/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>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Windows Service Options
<a class="headerlink leafygreen-ui-1kepx47" href="#windows-service-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="windows-service-options">
</div>
</a>
</h2>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"processManagement:\n windowsService:\n serviceName: <string>\n displayName: <string>\n description: <string>\n serviceUser: <string>\n servicePassword: <string>","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">processManagement:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">windowsService:</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serviceName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">displayName:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">description:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">serviceUser:</span> <span class="lg-highlight-string"><string></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">servicePassword:</span> <span class="lg-highlight-string"><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>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.serviceName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.windowsService.serviceName" 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-setting-processManagement.windowsService.serviceName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: MongoDB
</p>
<p class="leafygreen-ui-1kp3ins">
The service name of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
when running as a
Windows Service. Use this name with the
<code class="leafygreen-ui-1l06pbn">
net start <name>
</code>
and
<code class="leafygreen-ui-1l06pbn">
net stop <name>
</code>
operations.
</p>
<p class="leafygreen-ui-1kp3ins">
You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.windowsService.serviceName" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.serviceName
</code>
</span>
</a>
in conjunction with either
the
<code class="leafygreen-ui-1l06pbn">
--install
</code>
or
<code class="leafygreen-ui-1l06pbn">
--remove
</code>
option.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.displayName
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.windowsService.displayName" 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-setting-processManagement.windowsService.displayName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: MongoDB
</p>
<p class="leafygreen-ui-1kp3ins">
The name listed for MongoDB on the Services administrative
application.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.description
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.windowsService.description" 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-setting-processManagement.windowsService.description">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: MongoDB Server
</p>
<p class="leafygreen-ui-1kp3ins">
Run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
service description.
</p>
<p class="leafygreen-ui-1kp3ins">
You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.windowsService.description" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.description
</code>
</span>
</a>
in conjunction with the
<code class="leafygreen-ui-1l06pbn">
--install
</code>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
For descriptions that contain spaces, you must enclose the
description in quotes.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.serviceUser
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.windowsService.serviceUser" 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-setting-processManagement.windowsService.serviceUser">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
service in the context of a certain user. This
user must have "Log on as a service" privileges.
</p>
<p class="leafygreen-ui-1kp3ins">
You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.windowsService.serviceUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.serviceUser
</code>
</span>
</a>
in conjunction with the
<code class="leafygreen-ui-1l06pbn">
--install
</code>
option.
</p>
</dd>
</dl>
<dl class="setting">
<dt>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.servicePassword
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-setting-processManagement.windowsService.servicePassword" 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-setting-processManagement.windowsService.servicePassword">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The password for
<code class="leafygreen-ui-1l06pbn">
<user>
</code>
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</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>
when running with
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.windowsService.serviceUser" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.serviceUser
</code>
</span>
</a>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
You must use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-setting-processManagement.windowsService.servicePassword" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
processManagement.windowsService.servicePassword
</code>
</span>
</a>
in conjunction with the
<code class="leafygreen-ui-1l06pbn">
--install
</code>
option.
</p>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Removed MMAPv1 Options
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-mmapv1-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="removed-mmapv1-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB removed the deprecated MMAPv1 storage engine and the MMAPv1-specific
configuration options:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width: 60%;"/>
<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>
Removed Configuration File Setting
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Removed Command-line Option
</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">
storage.mmapv1.journal.commitIntervalMs
</code>
</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>
<code class="leafygreen-ui-1l06pbn">
storage.mmapv1.journal.debugFlags
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --journalOptions
</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">
storage.mmapv1.nsSize
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --nssize
</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">
storage.mmapv1.preallocDataFiles
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --noprealloc
</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">
storage.mmapv1.quota.enforced
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --quota
</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">
storage.mmapv1.quota.maxFilesPerDB
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --quotaFiles
</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">
storage.mmapv1.smallFiles
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --smallfiles
</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">
storage.repairPath
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --repairpath
</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">
replication.secondaryIndexPrefetch
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongod --replIndexPrefetch
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For earlier versions of MongoDB, refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/legacy/?site=docs" target="_self">
<span>
legacy documentation
</span>
</a>
.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/replSetResizeOplog/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
replSetResizeOplog
<a class="headerlink leafygreen-ui-1kepx47" href="#replsetresizeoplog" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replsetresizeoplog">
</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">
replSetResizeOplog
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.replSetResizeOplog" 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.replSetResizeOplog">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
also supports specifying the minimum number
of hours to preserve an oplog entry.
</p>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
5.0
</em>
:
<!-- -->
To set the
<code class="leafygreen-ui-1l06pbn">
replSetOplog
</code>
size 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>
, use
the
<code class="leafygreen-ui-1l06pbn">
Double()
</code>
constructor.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
enables you to resize the oplog or
its minimum retention period dynamically without restarting 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">
You must run this command against 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 is not supported in 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 form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n replSetResizeOplog: <int>,\n size: <double>,\n minRetentionHours: <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">replSetResizeOplog</span>: <<!-- -->int<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">size</span>: <<!-- -->double<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">minRetentionHours</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>
<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">
replSetResizeOplog
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
int
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Set to
<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">
size
</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>
<p class="leafygreen-ui-1kp3ins">
The maximum size of the oplog in megabytes.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The minimum size you can specify is 990 megabytes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The maximum size you can specify is 1 petabytes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Explicitly cast the
<code class="leafygreen-ui-1l06pbn">
size
</code>
as a double 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>
with
<code class="leafygreen-ui-1l06pbn">
Double()
</code>
. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-oplog-ex-change-size" target="_self">
<span>
Change the Maximum Oplog Size
<!-- -->
.
</span>
</a>
</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">
minRetentionHours
</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>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
. The minimum number of hours to preserve an oplog
entry, where decimal values represent the fractions of an
hour. For example, a value of
<code class="leafygreen-ui-1l06pbn">
1.5
</code>
represents one hour and
thirty minutes.
</p>
<p class="leafygreen-ui-1kp3ins">
The value must be greater than or equal to
<code class="leafygreen-ui-1l06pbn">
0
</code>
. A value of
<code class="leafygreen-ui-1l06pbn">
0
</code>
indicates that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
should
truncate the oplog starting with the oldest entries to
maintain the configured maximum oplog size.
</p>
<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>
configured with
<code class="leafygreen-ui-1l06pbn">
minRetentionHours
</code>
only removes an oplog entry
<em>
if
</em>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog has reached the maximum configured size,
<em>
and
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog entry is older that the configured number of
hours based on the host system clock.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To check the currently configured minimum oplog retention
period, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.oplogTruncation.oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
oplogTruncation.oplogMinRetentionHours
</code>
</a>
in the
output of 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.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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/program/mongod/#std-option-mongod.--oplogSize">
<code class="leafygreen-ui-1l06pbn">
--oplogSize
</code>
</a>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.oplogSizeMB">
<code class="leafygreen-ui-1l06pbn">
replication.oplogSizeMB
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
--oplogMinRetentionHours
</code>
</a>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
storage.oplogMinRetentionHours
</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>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
on
<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 the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
Wired Tiger storage engine
</a>
or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/change-oplog-size/#std-label-tutorial-change-oplog-size">
Change the Oplog Size of Self-Managed Replica Set Members
</a>
tutorial for a procedure
on using
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
command to resize the oplog.
</p>
<p class="leafygreen-ui-1kp3ins">
The oplog can grow past its configured size
limit to avoid deleting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
<code class="leafygreen-ui-1l06pbn">
majority commit point
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot drop the
<code class="leafygreen-ui-1l06pbn">
local.oplog.rs
</code>
collection. For more information on this
restriction, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-oplog-coll-behavior">
Oplog Collection Behavior
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
overrides the maximum oplog size or
minimum oplog retention period set at startup by:
</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-replication.oplogSizeMB">
<code class="leafygreen-ui-1l06pbn">
replication.oplogSizeMB
</code>
</a>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--oplogSize">
<code class="leafygreen-ui-1l06pbn">
--oplogSizeMB
</code>
</a>
, and
</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-storage.oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
storage.oplogMinRetentionHours
</code>
</a>
/
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
--oplogMinRetentionHours
</code>
</a>
respectively.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The new oplog size persists after a server restart, unless
you use:
</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-storage.oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
storage.oplogMinRetentionHours
</code>
</a>
, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
--oplogMinRetentionHours
</code>
.
</a>
</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">
Reducing the maximum oplog size results in truncation of the oldest
oplog entries until the oplog reaches the new configured size.
</p>
<p class="leafygreen-ui-1kp3ins">
Similarly, reducing the minimum oplog retention period
results in truncation of oplog entries older that the specified
period
<em>
if
</em>
the oplog has exceeded the maximum configured size.
</p>
<p class="leafygreen-ui-1kp3ins">
Oplog truncation due to reduced oplog size or retention period can
result in unexpected behavior from clients still reading those oplog
entries, including:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Open
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change streams
</a>
may become
invalidated
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Secondaries which have not replicated those oplog entries
may require
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-sync/#std-label-replica-set-initial-sync">
resynchronization
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Backups using
<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>
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>
against the member may
not capture entries prior to truncation.
</p>
</li>
</ul>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetResizeOplog-cmd-minimum-retention">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Minimum Oplog Retention Period
<a class="headerlink leafygreen-ui-1kepx47" href="#minimum-oplog-retention-period" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="minimum-oplog-retention-period">
</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>
has the following behavior when configured with
a minimum oplog retention period:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The oplog can grow without constraint so as to retain oplog entries
for the configured number of hours. This may result in reduction or
exhaustion of system disk space due to a combination of high write
volume and large retention period.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the oplog grows beyond its maximum size, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
may continue to hold that disk space even if the oplog returns to its
maximum size
<em>
or
</em>
is configured for a smaller maximum size. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetResizeOplog-cmd-compact" target="_self">
<span>
Reducing Oplog Size Does Not Immediately Return Disk Space
<!-- -->
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
compares the system wall clock to an
oplog entries creation wall clock time when enforcing oplog entry
retention. Clock drift between cluster components may result in
unexpected oplog retention behavior. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-production-notes-clock-synchronization">
Clock Synchronization
</a>
for more information on
clock synchronization across cluster members.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
Does Not Replicate To Other Members
<a class="headerlink leafygreen-ui-1kepx47" href="#replsetresizeoplog-does-not-replicate-to-other-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="replsetresizeoplog-does-not-replicate-to-other-members">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Changing the oplog size or minimum oplog retention period
of a given replica set member with
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
does
not change the oplog size of any other member in the replica set. You
must run
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
on each replica set member in
your cluster to change the oplog size or minimum retention period for
all members.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetResizeOplog-cmd-compact">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Reducing Oplog Size Does Not Immediately Return Disk Space
<a class="headerlink leafygreen-ui-1kepx47" href="#reducing-oplog-size-does-not-immediately-return-disk-space" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="reducing-oplog-size-does-not-immediately-return-disk-space">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Reducing the oplog size does not immediately reclaim that disk space.
This includes oplog size reduction due to truncation of oplog events
older than of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetResizeOplog-cmd-minimum-retention" target="_self">
<span>
minimum oplog retention period
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To immediately free unused disk space after reducing the oplog size, run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#mongodb-dbcommand-dbcmd.compact">
<code class="leafygreen-ui-1l06pbn">
compact
</code>
</a>
against the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database during a maintenance period.
<code class="leafygreen-ui-1l06pbn">
compact
</code>
blocks all
operations on the database it runs against. Running
<code class="leafygreen-ui-1l06pbn">
compact
</code>
against
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
therefore prevents oplog synchronization. For a procedure
on resizing the oplog and compacting
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/change-oplog-size/">
Change the Oplog Size of Self-Managed Replica Set Members
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Resource Locking
<a class="headerlink leafygreen-ui-1kepx47" href="#resource-locking" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
takes an exclusive (W) lock on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#mongodb-data-local.oplog.rs">
<code class="leafygreen-ui-1l06pbn">
oplog
</code>
</a>
and blocks other operations on the collection
until it finishes.
</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>
<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-oplog-ex-change-size">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change the Maximum Oplog Size
<a class="headerlink leafygreen-ui-1kepx47" href="#change-the-maximum-oplog-size" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-maximum-oplog-size">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</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 to display the current maximum oplog size,
<code class="leafygreen-ui-1l06pbn">
maxSize
</code>
, in
megabytes. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"local\").oplog.rs.stats(1024*1024).maxSize","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">getSiblingDB</span>(<span class="lg-highlight-string">"local"</span>).<span class="lg-highlight-property">oplog</span>.<span class="lg-highlight-property">rs</span>.<span class="lg-highlight-title lg-highlight-function">stats</span>(<span class="lg-highlight-number">1024</span>*<span class="lg-highlight-number">1024</span>).<span class="lg-highlight-property">maxSize</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 above command returns the oplog size of this member in megabytes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"990","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-number">990</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 uses
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
to change the
oplog size of this member to 16384 megabytes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({ \"replSetResizeOplog\": 1, size: Double(16384)})","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-string">"replSetResizeOplog"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-title lg-highlight-class">Double</span>(<span class="lg-highlight-number">16384</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 verify the new oplog size, rerun the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"local\").oplog.rs.stats(1024*1024).maxSize","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">getSiblingDB</span>(<span class="lg-highlight-string">"local"</span>).<span class="lg-highlight-property">oplog</span>.<span class="lg-highlight-property">rs</span>.<span class="lg-highlight-title lg-highlight-function">stats</span>(<span class="lg-highlight-number">1024</span>*<span class="lg-highlight-number">1024</span>).<span class="lg-highlight-property">maxSize</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 above command returns:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\"maxSize\": NumberLong(\"16834\")","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">"maxSize"</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"16834"</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">
Reducing the size of the oplog in a node removes data from it. This
may cause replica members syncing with that node to become stale.
To resync those members, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/resync-replica-set-member/">
Resync a Member of a Self-Managed Replica Set
<!-- -->
.
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change the Minimum Oplog Retention Period
<a class="headerlink leafygreen-ui-1kepx47" href="#change-the-minimum-oplog-retention-period" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-minimum-oplog-retention-period">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="1">
<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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
replica set member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
. Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.serverStatus/#mongodb-method-db.serverStatus">
<code class="leafygreen-ui-1l06pbn">
db.serverStatus()
</code>
</a>
command to verify
the current minimum oplog retention value as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.oplogTruncation.oplogMinRetentionHours">
<code class="leafygreen-ui-1l06pbn">
oplogTruncation.oplogMinRetentionHours
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").serverStatus().oplogTruncation.oplogMinRetentionHours","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">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</span>).<span class="lg-highlight-title lg-highlight-function">serverStatus</span>(<!-- -->).<span class="lg-highlight-property">oplogTruncation</span>.<span class="lg-highlight-property">oplogMinRetentionHours</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 currently configured minimum oplog retention
period for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"1.5","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-number">1.5</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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
has no minimum oplog retention period,
the operation returns an empty result.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
command to modify the
configured minimum oplog retention period. For example, the following
sets the minimum oplog retention period to
<code class="leafygreen-ui-1l06pbn">
2
</code>
hours:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({\n \"replSetResizeOplog\" : 1,\n \"minRetentionHours\" : 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-title lg-highlight-function">adminCommand</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"replSetResizeOplog"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"minRetentionHours"</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>
</li>
</ol>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/replSetStepDown/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
replSetStepDown
<a class="headerlink leafygreen-ui-1kepx47" href="#replsetstepdown" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replsetstepdown">
</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="#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">
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="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.replSetStepDown" 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.replSetStepDown">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Instructs the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
of the replica set to become a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
. After the primary steps down, eligible secondaries will
hold an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-election-internals">
election for primary
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
command
<!-- -->
does not immediately step down the primary. If no
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.priority">
<code class="leafygreen-ui-1l06pbn">
electable
</code>
</a>
secondaries
are up to date with the primary, the primary waits up to
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
(by default 10 seconds) for a
secondary to catch up. Once an electable secondary is
available, the
<!-- -->
command
<!-- -->
steps down the primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Once stepped down, the original primary becomes a secondary and is
ineligible from becoming primary again for the remainder of time
specified by
<code class="leafygreen-ui-1l06pbn">
replSetStepDown: <seconds>
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For a detailed explanation of the
<!-- -->
command
<!-- -->
's execution,
see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetStepDown-behavior" target="_self">
<span>
Behavior
</span>
</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">
The
<!-- -->
command
<!-- -->
is only valid against the primary and throws an
error if run on a non-primary member.
</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">
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/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</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">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
can only run on 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 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 replSetStepDown: <seconds>,\n secondaryCatchUpPeriodSecs: <seconds>,\n force: <true|false>\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">replSetStepDown</span>: <<!-- -->seconds<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">secondaryCatchUpPeriodSecs</span>: <<!-- -->seconds<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">force</span>: <span class="lg-highlight-xml"><true|false></span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><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>
</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">
replSetStepDown
</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>
<p class="leafygreen-ui-1kp3ins">
The number of seconds to step down the primary, during which time the
stepdown member is ineligible for becoming primary. If you specify a
non-numeric value, the command uses
<code class="leafygreen-ui-1l06pbn">
60
</code>
seconds.
</p>
<p class="leafygreen-ui-1kp3ins">
The stepdown period starts from the time that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
receives the command. The stepdown period must
be greater than the
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</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>
<p class="leafygreen-ui-1kp3ins">
Optional. The number of seconds that 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 wait for
an electable secondary to catch up to the primary.
</p>
<p class="leafygreen-ui-1kp3ins">
When specified,
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
overrides the default
wait time of either
<code class="leafygreen-ui-1l06pbn">
10
</code>
seconds or if
<code class="leafygreen-ui-1l06pbn">
force: true
</code>
,
<code class="leafygreen-ui-1l06pbn">
0
</code>
seconds.
</p>
</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">
Optional. A boolean that determines whether the primary steps down if no electable
and up-to-date secondary exists within the wait period.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the primary steps down even if no suitable secondary
member exists; this could lead to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/">
rollbacks
</a>
if a secondary with replication lag
becomes the new primary.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, the primary does not step down if no suitable secondary
member exists and the command returns an error.
</p>
<p class="leafygreen-ui-1kp3ins">
Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetStepDown-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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Concurrent Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#concurrent-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="concurrent-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
attempts to
terminate long running user operations that block the primary
from stepping down, such as an index build, a write operation or a
map-reduce job.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Availability of Eligible Secondaries
<a class="headerlink leafygreen-ui-1kepx47" href="#availability-of-eligible-secondaries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="availability-of-eligible-secondaries">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
command
<!-- -->
then initiates a catchup period where it waits up to
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSeconds
</code>
, by default 10 seconds, for a
secondary to become up-to-date with the primary. The primary only steps
down if a secondary is up-to-date with the primary during the
catchup period to prevent
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-rollbacks/#std-label-replica-set-rollbacks">
rollbacks
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If no electable secondary meets this criterion by the end of the waiting
period, the primary does not step down and the
<!-- -->
command
<!-- -->
errors.
<!-- -->
You can override this behavior and issue with command with the
<code class="leafygreen-ui-1l06pbn">
force: true
</code>
option to immediately step down the primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Once the primary steps down successfully, that node cannot become the
primary for the remainder of the
<code class="leafygreen-ui-1l06pbn">
replSetStepDown: <seconds>
</code>
period,
which began when the node received the
<!-- -->
command
<!-- -->
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Client Connections
<a class="headerlink leafygreen-ui-1kepx47" href="#client-connections" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-connections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
doesn't close all client
connections.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Writes During Stepdown
<a class="headerlink leafygreen-ui-1kepx47" href="#writes-during-stepdown" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="writes-during-stepdown">
</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">
All writes to the primary fail during the period starting when the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
is received until either a new
primary is elected, or if there are no electable secondaries, the
original primary resumes normal operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Writes that were in progress when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
is run
are killed. In-progress
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
transactions
</a>
also fail with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transient-transaction-error">
<code class="leafygreen-ui-1l06pbn">
TransientTransactionError
</code>
</a>
and can be
retried as a whole.
</p>
<p class="leafygreen-ui-1kp3ins">
The time period where writes fail is at maximum:
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
(10s by default) +
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.electionTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
electionTimeoutMillis
</code>
</a>
(10s by default).
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Election Handoff
<a class="headerlink leafygreen-ui-1kepx47" href="#election-handoff" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="election-handoff">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you step down a primary using
<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>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
without setting the
<code class="leafygreen-ui-1l06pbn">
force
</code>
field to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the stepped-down primary nominates an eligible secondary
to call an election immediately.
</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">
Step Down with Default Options
<a class="headerlink leafygreen-ui-1kepx47" href="#step-down-with-default-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="step-down-with-default-options">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example, run on the current primary, attempts to step
down the member for
<code class="leafygreen-ui-1l06pbn">
120
</code>
seconds.
</p>
<p class="leafygreen-ui-1kp3ins">
The operation waits up to the default
<code class="leafygreen-ui-1l06pbn">
10
</code>
seconds for a
secondary to catch up. If no suitable secondary exists, the primary
does not step down and the command errors.
</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">
All writes to the primary fail during the period starting when the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
is received until either a new
primary is elected, or if there are no electable secondaries, the
original primary resumes normal operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Writes that were in progress when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
is run
are killed. In-progress
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
transactions
</a>
also fail with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transient-transaction-error">
<code class="leafygreen-ui-1l06pbn">
TransientTransactionError
</code>
</a>
and can be
retried as a whole.
</p>
<p class="leafygreen-ui-1kp3ins">
The time period where writes fail is at maximum:
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
(10s by default) +
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.electionTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
electionTimeoutMillis
</code>
</a>
(10s by default).
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { replSetStepDown: 120 } )","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">replSetStepDown</span>: <span class="lg-highlight-number">120</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 Wait Time for Secondary Catch Up
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-wait-time-for-secondary-catch-up" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-wait-time-for-secondary-catch-up">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example, run on the current primary, attempts to step
down the member for
<code class="leafygreen-ui-1l06pbn">
120
</code>
seconds, waiting up to
<code class="leafygreen-ui-1l06pbn">
15
</code>
seconds for
an electable secondary to catch up. If no suitable secondary exists,
the primary does not step down and the command errors.
</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">
All writes to the primary fail during the period starting when the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
is received until either a new
primary is elected, or if there are no electable secondaries, the
original primary resumes normal operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Writes that were in progress when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
is run
are killed. In-progress
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
transactions
</a>
also fail with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transient-transaction-error">
<code class="leafygreen-ui-1l06pbn">
TransientTransactionError
</code>
</a>
and can be
retried as a whole.
</p>
<p class="leafygreen-ui-1kp3ins">
The time period where writes fail is at maximum:
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
(10s by default) +
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.electionTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
electionTimeoutMillis
</code>
</a>
(10s by default).
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15 } )","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">replSetStepDown</span>: <span class="lg-highlight-number">120</span>, <span class="lg-highlight-attr">secondaryCatchUpPeriodSecs</span>: <span class="lg-highlight-number">15</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 Secondary Catch Up with Force Step Down
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-secondary-catch-up-with-force-step-down" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-secondary-catch-up-with-force-step-down">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example, run on the current primary, attempts to step
down the member for
<code class="leafygreen-ui-1l06pbn">
120
</code>
seconds, waiting up to
<code class="leafygreen-ui-1l06pbn">
15
</code>
seconds for
an electable secondary to catch up. Because of the
<code class="leafygreen-ui-1l06pbn">
force: true
</code>
option, the primary steps down even if no suitable secondary exists.
</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">
All writes to the primary fail during the period starting when the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
<!-- -->
command
<!-- -->
is received until either a new
primary is elected, or if there are no electable secondaries, the
original primary resumes normal operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Writes that were in progress when
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetStepDown" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</span>
</a>
is run
are killed. In-progress
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
transactions
</a>
also fail with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-in-applications/#std-label-transient-transaction-error">
<code class="leafygreen-ui-1l06pbn">
TransientTransactionError
</code>
</a>
and can be
retried as a whole.
</p>
<p class="leafygreen-ui-1kp3ins">
The time period where writes fail is at maximum:
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
secondaryCatchUpPeriodSecs
</code>
(10s by default) +
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.electionTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
electionTimeoutMillis
</code>
</a>
(10s by default).
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { replSetStepDown: 120, secondaryCatchUpPeriodSecs: 15, force: 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>( <!-- -->{ <span class="lg-highlight-attr">replSetStepDown</span>: <span class="lg-highlight-number">120</span>, <span class="lg-highlight-attr">secondaryCatchUpPeriodSecs</span>: <span class="lg-highlight-number">15</span>, <span class="lg-highlight-attr">force</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-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/method/rs.stepDown/#mongodb-method-rs.stepDown">
<code class="leafygreen-ui-1l06pbn">
rs.stepDown()
</code>
</a>
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/replSetReconfig/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
replSetReconfig
<a class="headerlink leafygreen-ui-1kepx47" href="#replsetreconfig" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replsetreconfig">
</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="#additional-information" target="_self">
<span>
Additional Information
</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">
replSetReconfig
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.replSetReconfig" 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.replSetReconfig">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
administrative command modifies the
configuration of an existing replica set. You can use this command to
add and remove members, and to alter the options set on existing
members. You must run this command on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
replica set member.
</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/rs.reconfig/#mongodb-method-rs.reconfig">
<code class="leafygreen-ui-1l06pbn">
rs.reconfig()
</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 replSetReconfig: <new_config_document>,\n force: <boolean>,\n maxTimeMS: <int>\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">replSetReconfig</span>: <<!-- -->new_config_document<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">force</span>: <<!-- -->boolean<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">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>
</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 optional field:
</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="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetReconfig-cmd-force">
</span>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-force" target="_self">
<span>
force
</span>
</a>
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
. Specify
<code class="leafygreen-ui-1l06pbn">
true
</code>
to force the
available replica set members to accept the new configuration.
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetReconfig-cmd-maxTimeMS">
</span>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-maxTimeMS" target="_self">
<span>
maxTimeMS
</span>
</a>
</p>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Optional. Specifies a cumulative time limit in milliseconds
for processing the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
. By default,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
waits indefinitely for the
replica configuration to propagate to a majority of replica
set members. Setting
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
may result
in the operation failing
<em>
before
</em>
it can apply the new
configuration. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-majority-install" target="_self">
<span>
Reconfiguration Waits Until a Majority of Members Install the Replica Configuration
</span>
</a>
for more information.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
You may also run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
with the shell's
<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>
method.
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Global Write Concern
<a class="headerlink leafygreen-ui-1kepx47" href="#global-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="global-write-concern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, you must explicitly set the global default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
before attempting to reconfigure a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#std-label-replica-set-configuration-settings">
configuration
</a>
that would change the implicit default write concern. To set the global
default 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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
term
</code>
Replica Configuration Field
<a class="headerlink leafygreen-ui-1kepx47" href="#term-replica-configuration-field" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="term-replica-configuration-field">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
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 is set by the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
replica set member.
The primary ignores 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 if set explicitly in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
operation.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetReconfig-cmd-single-node">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Reconfiguration Can Add or Remove No More than One Voting Member at a Time
<a class="headerlink leafygreen-ui-1kepx47" href="#reconfiguration-can-add-or-remove-no-more-than-one-voting-member-at-a-time" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="reconfiguration-can-add-or-remove-no-more-than-one-voting-member-at-a-time">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
by default allows adding or
removing no more than
<code class="leafygreen-ui-1l06pbn">
1
</code>
<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>
member at a time. For example, a new configuration can make at most
<em>
one
</em>
of the following changes to the cluster
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.votes">
<code class="leafygreen-ui-1l06pbn">
membership
</code>
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Adding a new voting replica set member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Removing an existing voting replica set member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Modifying the
<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>
for an existing replica
set member.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To add or remove multiple voting members, issue a series of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
operations to add or remove one member at a
time.
</p>
<p class="leafygreen-ui-1kp3ins">
Issuing a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-force" target="_self">
<span>
force
</span>
</a>
reconfiguration
immediately installs the new configuration even if it adds or removes
multiple voting members. Force reconfiguration can cause unexpected
behavior, such as the rollback 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 write operations.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetReconfig-cmd-majority-install">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Reconfiguration Waits Until a Majority of Members Install the Replica Configuration
<a class="headerlink leafygreen-ui-1kepx47" href="#reconfiguration-waits-until-a-majority-of-members-install-the-replica-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="reconfiguration-waits-until-a-majority-of-members-install-the-replica-configuration">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
waits until a majority of voting
replica set members install the new replica configuration before
returning success. A voting member is
<em>
any
</em>
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
<code class="leafygreen-ui-1l06pbn">
1
</code>
, including arbiters.
</p>
<p class="leafygreen-ui-1kp3ins">
Replica set members propagate their replica configuration via
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-heartbeats">
heartbeats
</a>
. Whenever a member learns
of a configuration with a higher
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.version">
<code class="leafygreen-ui-1l06pbn">
version
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.term">
<code class="leafygreen-ui-1l06pbn">
term
</code>
</a>
, it installs the new configuration. The
reconfiguration process has two distinct 'waiting' phases:
</p>
<dl>
<dt>
1) Wait for the current configuration to be
<em>
committed
</em>
before installing the new configuration.
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
The "current" configuration refers to the replica configuration in
use by the primary at the time
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
is issued.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetReconfig-configuration-committed">
</span>
<p class="leafygreen-ui-1kp3ins">
A configuration is committed when:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A majority of voting replica set members have installed the
current configuration,
<em>
and
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
All writes which were
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
committed in
the previous configuration have also replicated to a majority in
the current configuration.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Typically, the current configuration has already been installed on
a majority of voting replica set members. However, the majority
committed writes in the previous configuration may not all be
committed in the current configuration.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs">
<code class="leafygreen-ui-1l06pbn">
Delayed
</code>
</a>
members
<em>
or
</em>
members that are
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.printSecondaryReplicationInfo/#mongodb-method-rs.printSecondaryReplicationInfo">
<code class="leafygreen-ui-1l06pbn">
lagging behind
</code>
</a>
the
primary can increase the time spent in this phase.
</p>
<p class="leafygreen-ui-1kp3ins">
If the operation was issued with a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-maxTimeMS" target="_self">
<span>
maxTimeMS
</span>
</a>
limit
<em>
and
</em>
the operation exceeds the limit while waiting, the operation
returns an error and discard the new configuration. The
limit is
<em>
cumulative
</em>
and does not reset after proceeding to
the next phase.
</p>
</dd>
<dt>
2) Wait for a majority of voting members in the new configuration to install the new configuration.
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
The "new" configuration refers to the replica configuration
specified to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The primary installs and begins using the new replica
configuration before propagating the configuration to the
remaining replica set members. The operation only waits for a
majority of voting members to install the new configuration, and
does not require waiting for the new configuration to be
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-configuration-committed" target="_self">
<span>
committed
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If the operation was issued with a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-maxTimeMS" target="_self">
<span>
maxTimeMS
</span>
</a>
limit
<em>
and
</em>
the operation exceeds the limit while waiting, the operation
returns an error
<em>
but
</em>
continues using and propagating the new
configuration.
</p>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Issuing a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replSetReconfig-cmd-force" target="_self">
<span>
force
</span>
</a>
reconfiguration
immediately installs the new configuration regardless of the
commitment status of the previous configuration. Force
reconfiguration can cause unexpected behavior, such as the
rollback 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 write operations.
</p>
<p class="leafygreen-ui-1kp3ins">
To check the commitment status of the current replica configuration,
issue
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#mongodb-dbcommand-dbcmd.replSetGetConfig">
<code class="leafygreen-ui-1l06pbn">
replSetGetConfig
</code>
</a>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#std-label-replSetGetConfig-commitmentStatus">
commitmentStatus
</a>
parameter
on the replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Automatic Reconfiguration for New Voting Replica Set Members
<a class="headerlink leafygreen-ui-1kepx47" href="#automatic-reconfiguration-for-new-voting-replica-set-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="automatic-reconfiguration-for-new-voting-replica-set-members">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, a newly added secondary does not count as a
voting member and cannot be elected until it has reached the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state.
</p>
<p class="leafygreen-ui-1kp3ins">
When a new voting node is added to a replica set,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
will internally add a
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field to the node's configuration. Nodes with the
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field
do not count towards the current number of voting nodes. When initial
sync completes and the node reaches
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state, the
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field is automatically removed.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Configurations that attempt to add a field named
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
will error even if run with
<code class="leafygreen-ui-1l06pbn">
{ force: true }
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If an existing node has a
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field, using
<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 change the configuration will not
remove the
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
field will be
appended to the user provided configuration.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetConfig/#mongodb-dbcommand-dbcmd.replSetGetConfig">
<code class="leafygreen-ui-1l06pbn">
replSetGetConfig
</code>
</a>
will remove any
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
fields
from its output. If you would like to see any
<code class="leafygreen-ui-1l06pbn">
newlyAdded
</code>
fields, you can query the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#mongodb-data-local.system.replset">
<code class="leafygreen-ui-1l06pbn">
local.system.replset
</code>
</a>
collection
directly.
</p>
</li>
</ul>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<p class="leafygreen-ui-1kp3ins">
To run the command on deployments that enforce
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/">
access
control
</a>
, the user must have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-replSetConfigure">
<code class="leafygreen-ui-1l06pbn">
replSetConfigure
</code>
</a>
privilege action on the cluster
resource. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
<code class="leafygreen-ui-1l06pbn">
clusterManager
</code>
</a>
built-in role, available in
the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database, provides the required privileges for this
command.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Locking Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#locking-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="locking-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
obtains a special mutually
exclusive lock to prevent more than one
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
operation from occurring at the same
time.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Mixed Version Replica Set
<a class="headerlink leafygreen-ui-1kepx47" href="#mixed-version-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="mixed-version-replica-set">
</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">
Avoid reconfiguring replica sets that contain members of different
MongoDB versions as validation rules may differ across MongoDB versions.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Availability
<a class="headerlink leafygreen-ui-1kepx47" href="#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="availability">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
A majority of the set's members must be operational for the changes to
propagate properly.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
can trigger the current
primary to step down in some situations. Primary step-down triggers
an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
election
</a>
to select a new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When the new primary steps up, it increments 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
distinguish configuration changes made on the new primary from changes made
on the previous primary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When the primary steps down, it no longer
closes all client connections; however, writes that were in progress
are killed. For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetStepDown/#std-label-replSetStepDown-behavior">
Behavior
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The median time before a cluster elects a new primary should not
typically exceed 12 seconds, assuming default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings">
<code class="leafygreen-ui-1l06pbn">
replica
configuration settings
</code>
</a>
. This includes time required to
mark the primary as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/replication/#std-label-replication-auto-failover">
unavailable
</a>
and
call and complete an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
election
</a>
.
You can tune this time period by modifying the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.electionTimeoutMillis">
<code class="leafygreen-ui-1l06pbn">
settings.electionTimeoutMillis
</code>
</a>
replication configuration
option. Factors such as network latency may extend the time required
for replica set elections to complete, which in turn affects the amount
of time your cluster may operate without a primary. These factors are
dependent on your particular cluster architecture.
</p>
<p class="leafygreen-ui-1kp3ins">
During the election process, the cluster cannot
accept write operations until it elects the new primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Your application connection logic should include tolerance for automatic
failovers and the subsequent elections. MongoDB drivers
can detect the loss of the primary and automatically
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/#std-label-retryable-writes">
retry certain write operations
</a>
a single time,
providing additional built-in handling of automatic failovers and elections:
</p>
<p class="leafygreen-ui-1kp3ins">
Compatible drivers enable retryable writes by default
</p>
<p class="leafygreen-ui-1kp3ins">
To further reduce potential impact to a production cluster,
reconfigure only during scheduled maintenance periods.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
{ force: true }
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#--force--true--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="--force--true--">
</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">
MongoDB does not synchronize a forced replica set reconfiguration
between the replica sets in a cluster. Using
<code class="leafygreen-ui-1l06pbn">
{ force: true }
</code>
can
lead to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-rollback">
rollback
</a>
of majority-committed writes and an
inconsistent sharded cluster. Exercise caution when you use this option.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Drop Outgoing Connections After Removing a Member
<a class="headerlink leafygreen-ui-1kepx47" href="#drop-outgoing-connections-after-removing-a-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="drop-outgoing-connections-after-removing-a-member">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.replSetReconfig" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</span>
</a>
to remove a replica set member does
not automatically drop open outgoing connections from other replica
set members to the removed member.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, replica set members wait for 5 minutes before dropping
connections to the removed member. In sharded replica sets, you can
modify this timeout using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ShardingTaskExecutorPoolHostTimeoutMS">
<code class="leafygreen-ui-1l06pbn">
ShardingTaskExecutorPoolHostTimeoutMS
</code>
</a>
server parameter.
</p>
<p class="leafygreen-ui-1kp3ins">
To immediately drop all outgoing connections from the replica set to
the removed member, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dropConnections/#mongodb-dbcommand-dbcmd.dropConnections">
<code class="leafygreen-ui-1l06pbn">
dropConnections
</code>
</a>
administrative command on each remaining member on the replica set:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand(\n {\n \"dropConnections\" : 1,\n \"hostAndPort\" : [\n \"<hostname>:<port>\"\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-string">"dropConnections"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hostAndPort"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<hostname>:<port>"</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">
Replace
<code class="leafygreen-ui-1l06pbn">
<hostname>
</code>
and
<code class="leafygreen-ui-1l06pbn">
<port>
</code>
with those of the removed
member.
</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">
Starting in MongDB 5.0,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Split-horizon_DNS" rel="noopener noreferrer">
<span>
split horizon DNS
</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>
nodes that are
only configured with an IP address fail startup validation and
report an error. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.disableSplitHorizonIPCheck">
<code class="leafygreen-ui-1l06pbn">
disableSplitHorizonIPCheck
</code>
.
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Member Priority and Votes
<a class="headerlink leafygreen-ui-1kepx47" href="#member-priority-and-votes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="member-priority-and-votes">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Members with
<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>
greater than 0 cannot have
0
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Non-voting (i.e.
<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>
is
<code class="leafygreen-ui-1l06pbn">
0
</code>
) members must have
<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>
of 0.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Information
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-information">
</div>
</a>
</h2>
<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>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/">
Self-Managed Replica Set Configuration
</a>
,
<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>
, and
<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>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/server-side-javascript/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Server-side JavaScript
<a class="headerlink leafygreen-ui-1kepx47" href="#server-side-javascript" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-side-javascript">
</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="#running-.js-files-via-a-mongosh-instance-on-the-server" target="_self">
<span>
Running
<code class="css-1kekw28 e1wawog0">
.js
</code>
files via a
<code class="css-1kekw28 e1wawog0">
mongosh
</code>
Instance on the Server
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#disable-server-side-execution-of-javascript" target="_self">
<span>
Disable Server-Side Execution of JavaScript
</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>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Server-side JavaScript Deprecated
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, server-side JavaScript functions
(
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
) are
deprecated. MongoDB logs a warning when you run these functions.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce">
Map-reduce
</a>
is deprecated starting in MongoDB 5.0.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides the following commands, methods, and operator that
perform server-side execution of JavaScript code:
</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/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
and the corresponding
<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.mapReduce/#mongodb-method-db.collection.mapReduce">
<code class="leafygreen-ui-1l06pbn">
db.collection.mapReduce()
</code>
</a>
. For more
information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/">
Map-Reduce
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
operator that evaluates a JavaScript expression or a
function in order to query for documents.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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
operations that allows users to define custom aggregation expressions.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You can also specify a JavaScript file 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>
to
run on the server. For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-running-js-scripts-in-mongo-on-mongod-host" target="_self">
<span>
Running
<code class="leafygreen-ui-1l06pbn">
.js
</code>
files via a
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
Instance on the Server
</span>
</a>
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
JavaScript in MongoDB
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Although these methods use JavaScript, most
interactions with MongoDB do not use JavaScript but use an
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
idiomatic driver
</span>
</a>
in the language
of the interacting application.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you do not need to perform server-side execution of JavaScript code,
see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-disable-server-side-js" target="_self">
<span>
Disable Server-Side Execution of JavaScript
<!-- -->
.
</span>
</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 you are using SELinux, any MongoDB operation that requires
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-server-side-javascript" target="_self">
<span>
server-side JavaScript
</span>
</a>
will
result in segfault errors.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-disable-server-side-js" target="_self">
<span>
Disable Server-Side Execution of JavaScript
</span>
</a>
describes
how to disable execution of server-side JavaScript.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-running-js-scripts-in-mongo-on-mongod-host">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Running
<code class="leafygreen-ui-1l06pbn">
.js
</code>
files via a
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
Instance on the Server
<a class="headerlink leafygreen-ui-1kepx47" href="#running-.js-files-via-a-mongosh-instance-on-the-server" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="running-.js-files-via-a-mongosh-instance-on-the-server">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can specify a JavaScript (
<code class="leafygreen-ui-1l06pbn">
.js
</code>
) file 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>
to execute the file on the server. This is a good technique
for performing batch administrative work. When you run
<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>
on the server, connecting via the localhost
interface, the connection is fast with low latency.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-disable-server-side-js">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Disable Server-Side Execution of JavaScript
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-server-side-execution-of-javascript" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-server-side-execution-of-javascript">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can disable all server-side execution of JavaScript:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance by passing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--noscripting">
<code class="leafygreen-ui-1l06pbn">
--noscripting
</code>
</a>
option on the command
line or setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.javascriptEnabled">
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
</a>
to false in the
configuration file.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For 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 by passing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-option-mongos.--noscripting">
<code class="leafygreen-ui-1l06pbn">
--noscripting
</code>
</a>
option on the command
line or setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.javascriptEnabled">
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
</a>
to false in the
configuration file.
</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>
<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">
Refer to the individual method or operator documentation for any
concurrency information. See also the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/faq/concurrency/#std-label-faq-concurrency-operations-locks">
concurrency table
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unsupported Array and String Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#unsupported-array-and-string-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unsupported-array-and-string-functions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 upgrades the internal JavaScript engine used for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-server-side-javascript" target="_self">
<span>
server-side JavaScript
</span>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
expressions and from MozJS-60 to MozJS-91. Several deprecated,
non-standard array and string functions that existed in MozJS-60 are
removed in MozJS-91.
</p>
<p class="leafygreen-ui-1kp3ins">
For the complete list of removed array and string functions, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-compatibility/#std-label-6.0-js-engine-change">
6.0 compatibility notes
<!-- -->
.
</a>
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/6.0-compatibility/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Compatibility Changes in MongoDB 6.0
<a class="headerlink leafygreen-ui-1kepx47" href="#compatibility-changes-in-mongodb-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="compatibility-changes-in-mongodb-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="#aggregation" target="_self">
<span>
Aggregation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#change-streams" target="_self">
<span>
Change Streams
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#indexes" target="_self">
<span>
Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#legacy-mongo-shell-removed" target="_self">
<span>
Legacy
<code class="css-1kekw28 e1wawog0">
mongo
</code>
Shell Removed
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#platform-support" target="_self">
<span>
Platform Support
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#regular-expressions" target="_self">
<span>
Regular Expressions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#removed-operators" target="_self">
<span>
Removed Operators
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#removed-options" target="_self">
<span>
Removed Options
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#removed-parameters" target="_self">
<span>
Removed Parameters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#renamed-parameters" target="_self">
<span>
Renamed Parameters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#ttl-expireafterseconds-behavior-when-set-to-nan" target="_self">
<span>
TTL
<code class="css-1kekw28 e1wawog0">
expireAfterSeconds
</code>
Behavior When Set to
<code class="css-1kekw28 e1wawog0">
NaN
</code>
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#replica-sets" target="_self">
<span>
Replica Sets
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#security" target="_self">
<span>
Security
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#time-series-collections" target="_self">
<span>
Time Series Collections
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#general-changes" target="_self">
<span>
General Changes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#downgrade-considerations" target="_self">
<span>
Downgrade Considerations
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page describes changes introduced in MongoDB 6.0 that can affect
compatibility with older versions of MongoDB.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 is a
<!-- -->
Major
<!-- -->
Release, which means that it is supported for
both MongoDB Atlas and on-premises deployments. MongoDB 6.0 includes
changes introduced in MongoDB Rapid Releases 5.1, 5.2, and 5.3. This
page describes compatibility changes introduced in those Rapid Releases
and MongoDB 6.0.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about the differences between
<!-- -->
Major
<!-- -->
and Rapid releases,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-release-version-numbers">
MongoDB Versioning
<!-- -->
.
</a>
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Aggregation
<a class="headerlink leafygreen-ui-1kepx47" href="#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="aggregation">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
allowDiskUse
</code>
Changes
<a class="headerlink leafygreen-ui-1kepx47" href="#allowdiskuse-changes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="allowdiskuse-changes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, pipeline stages that require more than 100
megabytes of memory to execute write temporary files to disk by
default. These temporary files last for the duration of the pipeline
execution and can influence storage space on your instance. In earlier
versions of MongoDB, you must pass
<code class="leafygreen-ui-1l06pbn">
{ allowDiskUse: true }
</code>
to
individual
<code class="leafygreen-ui-1l06pbn">
find
</code>
and
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
commands to enable this
behavior.
</p>
<p class="leafygreen-ui-1kp3ins">
Individual
<code class="leafygreen-ui-1l06pbn">
find
</code>
and
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
commands can override the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.allowDiskUseByDefault">
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
</a>
parameter by either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using
<code class="leafygreen-ui-1l06pbn">
{ allowDiskUse: true }
</code>
to allow writing temporary files out
to disk when
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
is set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Using
<code class="leafygreen-ui-1l06pbn">
{ allowDiskUse: false }
</code>
to prohibit writing temporary files
out to disk when
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
is set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$$SEARCH_META
</code>
Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#--search_meta-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="--search_meta-limitations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the Atlas Search
<code class="leafygreen-ui-1l06pbn">
$$SEARCH_META
</code>
aggregation variable
can be used anywhere after a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#mongodb-pipeline-pipe.-search" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$search
</code>
</span>
</a>
stage in any pipeline, but it
cannot be used after the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unionWith/#mongodb-pipeline-pipe.-unionWith">
<code class="leafygreen-ui-1l06pbn">
$unionWith
</code>
</a>
stage in
any pipeline. The
<code class="leafygreen-ui-1l06pbn">
$$SEARCH_META
</code>
aggregation variable cannot be used in any
subsequent stage after a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#mongodb-pipeline-pipe.-searchMeta" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$searchMeta
</code>
</span>
</a>
stage.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Change Streams
<a class="headerlink leafygreen-ui-1kepx47" href="#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="change-streams">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.3, during
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-range-migration-procedure">
range migration
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change stream
</a>
events are not generated for updates to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Filters
<a class="headerlink leafygreen-ui-1kepx47" href="#filters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="filters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, whenever possible,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-change-stream-modify-output">
match filters
</a>
are applied to change streams earlier
than in prior releases. This improves performance. However, when a
filter is narrowly defined, an earlier match may cause an operation that
succeeds in prior versions to fail in 6.0.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" 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>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Last Remaining Shard Key Index Cannot be Dropped Inadvertently
<a class="headerlink leafygreen-ui-1kepx47" href="#last-remaining-shard-key-index-cannot-be-dropped-inadvertently" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="last-remaining-shard-key-index-cannot-be-dropped-inadvertently">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, passing
<code class="leafygreen-ui-1l06pbn">
"*"
</code>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dropIndexes/#mongodb-dbcommand-dbcmd.dropIndexes">
<code class="leafygreen-ui-1l06pbn">
dropIndexes
</code>
</a>
or
<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>
drops all indexes
<strong>
except
</strong>
for the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
index and the last remaining shard key index, if one
exists. Attempts to explicitly drop the last remaining shard key index
raise an error.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Existing Indexes Can Be Dropped During an Index Build
<a class="headerlink leafygreen-ui-1kepx47" href="#existing-indexes-can-be-dropped-during-an-index-build" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-indexes-can-be-dropped-during-an-index-build">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.2, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dropIndexes/#mongodb-dbcommand-dbcmd.dropIndexes">
<code class="leafygreen-ui-1l06pbn">
dropIndexes
</code>
</a>
or
<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>
to drop existing indexes on the
same collection even if there is an index build in progress. In earlier
versions, attempting to drop a different index during an in-progress
index build results in a
<code class="leafygreen-ui-1l06pbn">
BackgroundOperationInProgressForNamespace
</code>
error.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
2dsphere Document Index Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#2dsphere-document-index-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="2dsphere-document-index-keys">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To prevent out of memory errors,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.indexMaxNumGeneratedKeysPerDocument">
<code class="leafygreen-ui-1l06pbn">
indexMaxNumGeneratedKeysPerDocument
</code>
</a>
limits the maximum
number of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/geospatial-queries/#std-label-geo-2dsphere">
2dsphere index keys
</a>
generated for a
single document.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.indexMaxNumGeneratedKeysPerDocument">
<code class="leafygreen-ui-1l06pbn">
indexMaxNumGeneratedKeysPerDocument
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Key Format
<a class="headerlink leafygreen-ui-1kepx47" href="#index-key-format" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-key-format">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, a change to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
key format was introduced. If you create a unique
index in MongoDB 6.0, the index won't work with MongoDB versions earlier
than 5.3.2 or 5.0.7.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
Shell Removed
<a class="headerlink leafygreen-ui-1kepx47" href="#legacy-mongo-shell-removed" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="legacy-mongo-shell-removed">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell is removed from MongoDB 6.0. The
replacement is
<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>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Platform Support
<a class="headerlink leafygreen-ui-1kepx47" href="#platform-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="platform-support">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1.2 the following platforms are no longer
supported:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Community Edition
<a class="headerlink leafygreen-ui-1kepx47" href="#community-edition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="community-edition">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<span class="leafygreen-ui-vm4wms" tabindex="0">
RHEL
</span>
-72-s390x
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Regular Expressions
<a class="headerlink leafygreen-ui-1kepx47" href="#regular-expressions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="regular-expressions">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
Find Queries No Longer Ignore Invalid Regex
<a class="headerlink leafygreen-ui-1kepx47" href="#-regex-find-queries-no-longer-ignore-invalid-regex" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-regex-find-queries-no-longer-ignore-invalid-regex">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, invalid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex options
</code>
</a>
options are no longer ignored. This change makes
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex options
</code>
</a>
more consistent with
the use of
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
in 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 and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/project-fields-from-query-results/#std-label-projection">
projection
</a>
queries.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$regex
</code>
Schema Validation Error Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#-regex-schema-validation-error-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="-regex-schema-validation-error-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, if a collection has
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/specify-query-expression-rules/#std-label-schema-validation-query-expression">
schema validation
</a>
rules that contain invalid
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex">
<code class="leafygreen-ui-1l06pbn">
$regex options
</code>
</a>
the server:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Prevents all insert and update operations until the schema validation
rules containing the invalid regex pattern are modified with 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.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Writes a warning error 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>
log file.
</p>
</li>
</ul>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Removed Operators
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-operators" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="removed-operators">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, these legacy query operators are removed:
</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>
Removed Operator
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Alternative
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$comment
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.comment/#mongodb-method-cursor.comment">
<code class="leafygreen-ui-1l06pbn">
cursor.comment()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$explain
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.explain/#mongodb-method-cursor.explain">
<code class="leafygreen-ui-1l06pbn">
cursor.explain()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$hint
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$max
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.max/#mongodb-method-cursor.max">
<code class="leafygreen-ui-1l06pbn">
cursor.max()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$maxTimeMS
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.maxTimeMS/#mongodb-method-cursor.maxTimeMS">
<code class="leafygreen-ui-1l06pbn">
cursor.maxTimeMS()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$min
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.min/#mongodb-method-cursor.min">
<code class="leafygreen-ui-1l06pbn">
cursor.min()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$orderby
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort">
<code class="leafygreen-ui-1l06pbn">
cursor.sort()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$query
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/js-cursor/#std-label-doc-cursor-methods">
Cursor Methods
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$returnKey
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.returnKey/#mongodb-method-cursor.returnKey">
<code class="leafygreen-ui-1l06pbn">
cursor.returnKey()
</code>
</a>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
$showDiskLoc
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.showRecordId/#mongodb-method-cursor.showRecordId">
<code class="leafygreen-ui-1l06pbn">
cursor.showRecordId()
</code>
</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">
db.getLastError()
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-legacy-op-codes-removed" target="_self">
<span>
Legacy Opcodes Removed
</span>
</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">
db.getLastErrorObj()
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-legacy-op-codes-removed" target="_self">
<span>
Legacy Opcodes Removed
</span>
</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">
getLastError
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-legacy-op-codes-removed" target="_self">
<span>
Legacy Opcodes Removed
</span>
</a>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Removed Options
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-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="removed-options">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 removes the
<code class="leafygreen-ui-1l06pbn">
--cpu
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
option.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Removed Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-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="removed-parameters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 removes the following server parameters:
</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>
Removed Parameter
</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/program/mongod/#std-option-mongod.--tlsFIPSMode">
<code class="leafygreen-ui-1l06pbn">
--tlsFIPSMode
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
This option is removed from the MongoDB Community Edition. It
is available in MongoDB Enterprise edition.
</p>
<p class="leafygreen-ui-1kp3ins">
FIPS was not a supported feature in MongoDB Community Edition.
If your installation made use of FIPS anyway, you will need to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-ssl/">
reconfigure your TLS/SSL connections
</a>
before upgrading.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Renamed Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#renamed-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="renamed-parameters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the following parameters have been renamed:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
wiredTigerConcurrentReadTransactions
</code>
is now
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.storageEngineConcurrentReadTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentReadTransactions
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
wiredTigerConcurrentWriteTransactions
</code>
is now
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.storageEngineConcurrentWriteTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentWriteTransactions
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
TTL
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
Behavior When Set to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#ttl-expireafterseconds-behavior-when-set-to-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="ttl-expireafterseconds-behavior-when-set-to-nan">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Setting
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/expire-data/#std-label-ttl-collections">
TTL
</a>
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
experiences a behavior change from MongoDB 4.4 to MongoDB 6.0 that
affects initial sync from MongoDB 4.4 and earlier and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongorestore
</code>
</span>
</a>
from MongoDB 4.4 and earlier. Performing
any of those actions causes an
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
of
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
to be
treated as an
<code class="leafygreen-ui-1l06pbn">
expireAfterSeconds
</code>
of
<code class="leafygreen-ui-1l06pbn">
0
</code>
. Immediate document
expiration may occur as a result.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Replica Sets
<a class="headerlink leafygreen-ui-1kepx47" href="#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="replica-sets">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Assert Cluster Wide Write Concern is Set When Starting or Adding Shard
<a class="headerlink leafygreen-ui-1kepx47" href="#assert-cluster-wide-write-concern-is-set-when-starting-or-adding-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="assert-cluster-wide-write-concern-is-set-when-starting-or-adding-shard">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, when starting, restarting or adding a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-components/#std-label-sharding-shards">
shard server
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShard/#mongodb-method-sh.addShard">
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</a>
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern">
Cluster Wide Write Concern (CWWC)
</a>
must be set.
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
CWWC
</code>
is not set and the shard is configured
such that the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
default write concern
</a>
is
<code class="leafygreen-ui-1l06pbn">
{ w : 1 }
</code>
the shard server will fail to start or be added
and returns an error.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-defaults/#std-label-default-wc-formula">
default write concern calculations
</a>
for
details on how the default write concern is calculated.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
rs.reconfig
</code>
Cluster Wide Write Concern Validation
<a class="headerlink leafygreen-ui-1kepx47" href="#rs.reconfig-cluster-wide-write-concern-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="rs.reconfig-cluster-wide-write-concern-validation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, you must set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern">
Cluster Wide Write Concern (CWWC)
</a>
prior to issuing any
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.reconfig/#mongodb-method-rs.reconfig">
<code class="leafygreen-ui-1l06pbn">
reconfigs
</code>
</a>
that would otherwise change the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
default write concern
</a>
of the new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
member.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Security
<a class="headerlink leafygreen-ui-1kepx47" href="#security" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="security">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Intra-Cluster Authentication
<a class="headerlink leafygreen-ui-1kepx47" href="#intra-cluster-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="intra-cluster-authentication">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.3,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/#std-label-authentication-scram-sha-1">
SCRAM-SHA-1
</a>
cannot be used for intra-cluster authentication. Only
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-scram/#std-label-authentication-scram-sha-256">
SCRAM-SHA-256
</a>
is supported.
</p>
<p class="leafygreen-ui-1kp3ins">
In previous MongoDB versions, SCRAM-SHA-1 and SCRAM-SHA-256 can both be
used for intra-cluster authentication, even if SCRAM is not explicitly
enabled.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
FIPS Mode Defaults SCRAM-SHA-1 Authentication to Off
<a class="headerlink leafygreen-ui-1kepx47" href="#fips-mode-defaults-scram-sha-1-authentication-to-off" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fips-mode-defaults-scram-sha-1-authentication-to-off">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, instances running in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-fips/#std-label-fips-overview">
FIPS mode
</a>
have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#std-label-authentication-parameters">
SCRAM-SHA-1 authentication mechanism
</a>
disabled by default. You can enable the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#std-label-authentication-parameters">
SCRAM-SHA-1 authentication
mechanism
</a>
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#std-label-set-parameter-authenticationMechanisms-code">
setParameter.authenticationMechanisms
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
This change will not affect drivers which target MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#mongodb-dbcommand-dbcmd.setFeatureCompatibilityVersion">
<code class="leafygreen-ui-1l06pbn">
setFeatureCompatibilityVersion
</code>
</a>
4.0+.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
OCSP Must be Enabled
<a class="headerlink leafygreen-ui-1kepx47" href="#ocsp-must-be-enabled" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ocsp-must-be-enabled">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, if
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ocspEnabled">
<code class="leafygreen-ui-1l06pbn">
ocspEnabled
</code>
</a>
is set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
during
initial sync, all nodes must be able to reach the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/#std-label-ocsp-support">
OCSP
</a>
responder.
</p>
<p class="leafygreen-ui-1kp3ins">
If a member fails in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
<code class="leafygreen-ui-1l06pbn">
STARTUP2
</code>
</a>
state, set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.tlsOCSPVerifyTimeoutSecs">
<code class="leafygreen-ui-1l06pbn">
tlsOCSPVerifyTimeoutSecs
</code>
</a>
to a value that is less than
<code class="leafygreen-ui-1l06pbn">
5
</code>
.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" 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>
</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">
If you create a sharded
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time series collection
</a>
in MongoDB 5.1 or greater, downgrading
to a version older than MongoDB 5.0.4 will result in data loss.
</p>
<p class="leafygreen-ui-1kp3ins">
Before downgrading to a version older than 5.0.4, drop all sharded
time series collections.
</p>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Secondary Indexes on Time Series Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#secondary-indexes-on-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="secondary-indexes-on-time-series-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If there are
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary-index">
secondary indexes
</a>
on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time
series collections
</a>
and you need to
downgrade the feature compatibility version (fCV), you must first drop
any secondary indexes that are incompatible with the downgraded fCV.
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>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
General Changes
<a class="headerlink leafygreen-ui-1kepx47" href="#general-changes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="general-changes">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Deprecations
<a class="headerlink leafygreen-ui-1kepx47" href="#deprecations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="deprecations">
</div>
</a>
</h3>
<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>
Deprecated
</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/method/db.collection.reIndex/#mongodb-method-db.collection.reIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.reIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.reIndex/#mongodb-method-db.collection.reIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.reIndex()
</code>
</a>
method is deprecated in
MongoDB v6.0.
</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/command/reIndex/#mongodb-dbcommand-dbcmd.reIndex">
<code class="leafygreen-ui-1l06pbn">
reIndex
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/reIndex/#mongodb-dbcommand-dbcmd.reIndex">
<code class="leafygreen-ui-1l06pbn">
reIndex
</code>
</a>
command is deprecated in MongoDB v6.0.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Simple Network Management Protocol (SNMP)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, SNMP is deprecated and will be removed in the
next release. To monitor your deployment, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/ops-manager/current/" target="_self">
<span>
MongoDB Ops Manager
</span>
</a>
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$mod
</code>
Error Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#-mod-error-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="-mod-error-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1 (and 5.0.4), the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/mod/#mongodb-query-op.-mod">
<code class="leafygreen-ui-1l06pbn">
$mod
</code>
</a>
operator returns an error if the
<code class="leafygreen-ui-1l06pbn">
divisor
</code>
or
<code class="leafygreen-ui-1l06pbn">
remainder
</code>
values
evaluate to certain values. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/mod/#std-label-mod-behavior">
$mod behavior
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-legacy-op-codes-removed">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Legacy Opcodes Removed
<a class="headerlink leafygreen-ui-1kepx47" href="#legacy-opcodes-removed" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="legacy-opcodes-removed">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 removes support for the following legacy opcodes and
database commands:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-insert">
OP_INSERT
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-delete">
OP_DELETE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-update">
OP_UPDATE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-kill-cursors">
OP_KILL_CURSORS
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-get-more">
OP_GET_MORE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
getLastError
</code>
</p>
</li>
</ul>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Upgrade Drivers
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To avoid disruption due to the removal of these opcodes,
<strong>
upgrade your
driver to the latest version
</strong>
.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you attempt to connect to a MongoDB 3.4 or older
<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 a MongoDB 5.1 or newer
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell, you
will receive an error message like the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Connection handshake failed. Is your mongod 3.4 or older?\n:: caused by :: network error while attempting to run command\n'isMaster' on host '127.0.0.1:27017'"}
</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">Connection handshake failed. Is your mongod 3.4 or older?</td></tr><tr class=""><td class="leafygreen-ui-7razhx">:: caused by :: network error while attempting to run command</td></tr><tr class=""><td class="leafygreen-ui-7razhx">'isMaster' on host '127.0.0.1:27017'</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
mongod Responses to Legacy Opcodes
<a class="headerlink leafygreen-ui-1kepx47" href="#mongod-responses-to-legacy-opcodes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mongod-responses-to-legacy-opcodes">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Since MongoDB 3.6, MongoDB drivers have used
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-wire-protocol/#std-label-wire-op-msg">
OP_MSG
</a>
instead of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
</a>
and the other legacy opcodes
and commands.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0:
</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/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
will close the connection and will not respond to:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-insert">
OP_INSERT
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-delete">
OP_DELETE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-update">
OP_UPDATE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-kill-cursors">
OP_KILL_CURSORS
</a>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
will keep the connection open and return an error for:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
getLastError
</code>
database command
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-get-more">
OP_GET_MORE
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
</a>
finds
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Most
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
</a>
<span class="leafygreen-ui-vm4wms" tabindex="0">
RPC
</span>
command messages
</p>
</li>
</ul>
</li>
</ul>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
OP_QUERY RPC Commands
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
</a>
<span class="leafygreen-ui-vm4wms" tabindex="0">
RPC
</span>
protocol may be used with the following commands:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
_isSelf
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
authenticate
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
buildinfo
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
buildInfo
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
hello
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
ismaster
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
isMaster
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
saslContinue
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
saslStart
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
All other commands will be rejected if issued as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/legacy-opcodes/#std-label-wire-op-query">
OP_QUERY
<!-- -->
.
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-6.0-js-engine-change">
</span>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Removed Deprecated Array and String Functions for Server-Side JavaScript
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-deprecated-array-and-string-functions-for-server-side-javascript" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="removed-deprecated-array-and-string-functions-for-server-side-javascript">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 upgrades the internal JavaScript engine used for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/server-side-javascript/#std-label-server-side-javascript">
server-side JavaScript
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/where/#mongodb-query-op.-where">
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</a>
expressions and from MozJS-60 to MozJS-91. Several deprecated,
non-standard array and string functions that existed in MozJS-60 are
removed in MozJS-91.
</p>
<p class="leafygreen-ui-1kp3ins">
For the complete list of removed array and string functions, see the
next sections on this page.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Only Static Functions are Removed
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Only
<em>
static
</em>
JavaScript functions are removed.
<em>
Prototype function
</em>
equivalents of the removed functions can still be used.
</p>
<p class="leafygreen-ui-1kp3ins">
For example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.concat(<array1>, <array2>)
</code>
is a static function and no
longer works in MongoDB 6.0.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
<array1>.concat(<array2>)
</code>
is a prototype function and still
works in MongoDB 6.0.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
This behavior applies to both removed array and removed string
functions.
</p>
</div>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Removed Array Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-array-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="removed-array-functions">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the following array functions are removed and
cannot be used in server-side JavaScript with
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
,
<code class="leafygreen-ui-1l06pbn">
$function
</code>
, and
<code class="leafygreen-ui-1l06pbn">
$where
</code>
expressions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.concat
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.every
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.filter
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.forEach
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.indexOf
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.join
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.lastIndexOf
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.map
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.pop
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.push
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.reduce
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.reduceRight
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.reverse
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.shift
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.slice
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.some
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.sort
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.splice
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Array.unshift
</code>
</p>
</li>
</ul>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Removed String Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-string-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="removed-string-functions">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the following array functions are removed and
cannot be used in server-side JavaScript with
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
,
<code class="leafygreen-ui-1l06pbn">
$function
</code>
, and
<code class="leafygreen-ui-1l06pbn">
$where
</code>
expressions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.charAt
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.charCodeAt
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.concat
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.contains
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.endsWith
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.includes
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.indexOf
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.lastIndexOf
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.localeCompare
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.match
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.normalize
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.replace
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.search
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.slice
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.split
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.startsWith
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.substr
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.substring
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.toLocaleLowerCase
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.toLocaleUpperCase
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.toLowerCase
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.toUpperCase
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.trim
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.trimLeft
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
String.trimRight
</code>
</p>
</li>
</ul>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Default
<code class="leafygreen-ui-1l06pbn">
db.stats()
</code>
Settings
<a class="headerlink leafygreen-ui-1kepx47" href="#default-db.stats---settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-db.stats---settings">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dbStats/#mongodb-dbcommand-dbcmd.dbStats">
<code class="leafygreen-ui-1l06pbn">
dbStats
</code>
</a>
command and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.stats/#mongodb-method-db.stats">
<code class="leafygreen-ui-1l06pbn">
db.stats()
</code>
</a>
method only report free space assigned to
collections if the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/dbStats/#std-label-dbStats-freeStorage">
freeStorage
</a>
parameter is
set to 1.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Index Filters and Collations
<a class="headerlink leafygreen-ui-1kepx47" href="#index-filters-and-collations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-filters-and-collations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, an index filter uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
previously set using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheSetFilter/#mongodb-dbcommand-dbcmd.planCacheSetFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheSetFilter
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, use query settings instead of adding
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
. Index filters are deprecated
starting in MongoDB 8.0.
</p>
<p class="leafygreen-ui-1kp3ins">
Query settings have more functionality than index filters. Also, index
filters aren't persistent and you cannot easily create index filters for
all cluster nodes. To add query settings and explore examples, 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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Arrays in Collections and Views with
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
Command
<a class="headerlink leafygreen-ui-1kepx47" href="#arrays-in-collections-and-views-with-distinct-command" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="arrays-in-collections-and-views-with-distinct-command">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
</a>
command returns the
same results for collections and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
views
</a>
when
using arrays.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#std-label-distinct-arrays-in-collections-and-views">
Arrays in Collections and Views
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-6.0-downgrade-considerations">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Downgrade Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-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="downgrade-considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following sections provide information for removing
backward-incompatible features from your deployment. If you are
downgrading from MongoDB
<!-- -->
6.0
<!-- -->
to an earlier version, review the
following sections to ensure that your deployment runs successfully
after downgrading.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Clustered Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#clustered-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="clustered-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.3, if you are using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/clustered-collections/#std-label-clustered-collections">
clustered collections
</a>
, you must drop those collections before you can
downgrade to an earlier MongoDB version.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
User Write Blocking
<a class="headerlink leafygreen-ui-1kepx47" href="#user-write-blocking" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-write-blocking">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, if you need to downgrade the feature
compatibility version, ensure you disable cluster-to-cluster replication
and user write blocking.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-setFeatureCompatibilityVersion-user-write-blocking">
Cluster-to-Cluster Sync and User Write Blocking
<!-- -->
.
</a>
</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-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="time-series-collections-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You must drop time series collections before downgrading:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 or later to MongoDB 5.0.7 or earlier.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB 5.3 to MongoDB 5.0.5 or earlier.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
Time Series Collections
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Cluster Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#cluster-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="cluster-parameters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, ensure that all
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setClusterParameter/#mongodb-dbcommand-dbcmd.setClusterParameter">
<code class="leafygreen-ui-1l06pbn">
setClusterParameter
</code>
</a>
operations have completed.
<span class="leafygreen-ui-vm4wms" tabindex="0">
fCV
</span>
downgrade cannot occur successfully if there are any ongoing
<code class="leafygreen-ui-1l06pbn">
setClusterParameter
</code>
operations on sharded clusters.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
SELinux Policy Data
<a class="headerlink leafygreen-ui-1kepx47" href="#selinux-policy-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="selinux-policy-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.1, you must run the following command from the
directory into which the SELinux policy was previously cloned before you
can downgrade to an earlier MongoDB version:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo make uninstall","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">sudo make uninstall</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Key Management Interoperability Protocol (KMIP) Settings
<a class="headerlink leafygreen-ui-1kepx47" href="#key-management-interoperability-protocol--kmip--settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-interoperability-protocol--kmip--settings">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, the default KMIP protocol version is 1.2. To use KMIP
version 1.0 or 1.1, 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>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.3 Enterprise, if you are using the following KMIP
settings, you must remove them from the configuration file before you
can downgrade to an earlier MongoDB version:
</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.kmip.keyStatePollingSeconds">
<code class="leafygreen-ui-1l06pbn">
security.kmip.keyStatePollingSeconds
</code>
</a>
</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.kmip.activateKeys">
<code class="leafygreen-ui-1l06pbn">
security.kmip.activateKeys
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Time-based Retention of Change Streams Pre- and Post-Image Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#time-based-retention-of-change-streams-pre--and-post-image-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-based-retention-of-change-streams-pre--and-post-image-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, if you are using
<code class="leafygreen-ui-1l06pbn">
changeStreamOptions.preAndPostImages.expireAfterSeconds
</code>
to control
time-based retention of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.watch/#std-label-db.collection.watch-change-streams-pre-and-post-images-example">
change streams pre- and post-image collections
</a>
, you
must ensure there are no active
<code class="leafygreen-ui-1l06pbn">
setClusterParameter
</code>
operations when
downgrading.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Audit Log Encryption Settings
<a class="headerlink leafygreen-ui-1kepx47" href="#audit-log-encryption-settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-encryption-settings">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0 Enterprise, if you are using audit log
encryption, you must remove the following settings from the
configuration file before you can downgrade to an earlier MongoDB
version:
</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>
</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.localAuditKeyFile">
<code class="leafygreen-ui-1l06pbn">
auditLog.localAuditKeyFile
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Existing encrypted audit logs remain encrypted, and you can keep any
procedures you have developed for storage and processing of encrypted
logs.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-encryption-at-rest/#std-label-security-encryption-at-rest-audit-log">
Audit Log
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change Streams with Document Pre- and Post-Images
<a class="headerlink leafygreen-ui-1kepx47" href="#change-streams-with-document-pre--and-post-images" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-streams-with-document-pre--and-post-images">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, if you are using document pre- and post-images
for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/#std-label-change-stream-output">
change streams
</a>
, you must disable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#std-label-collMod-change-stream-pre-and-post-images">
changeStreamPreAndPostImages
</a>
for each collection using
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 before you can downgrade to an earlier
MongoDB version.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change Streams with Expanded Events
<a class="headerlink leafygreen-ui-1kepx47" href="#change-streams-with-expanded-events" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-streams-with-expanded-events">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your application uses change streams, ensure that it does not require the
<code class="leafygreen-ui-1l06pbn">
showExpandedEvents
</code>
option, which will not be available after downgrade.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
LDAP with
<code class="leafygreen-ui-1l06pbn">
srv:
</code>
and
<code class="leafygreen-ui-1l06pbn">
srv_raw:
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#ldap-with-srv--and-srv_raw-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ldap-with-srv--and-srv_raw-">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your cluster's configuration is using the new
<code class="leafygreen-ui-1l06pbn">
"srv:"
</code>
or
<code class="leafygreen-ui-1l06pbn">
"srv_raw:"
</code>
URL types in its LDAP configuration, it will be unable
to restart after a downgrade. Remove the new URL types from your
cluster's configuration before downgrading.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Collections with Encrypted Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#collections-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="collections-with-encrypted-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You must drop collections that use encrypted fields before you
can complete the fCV downgrade. The downgrade will not complete
if there are collections using
<code class="leafygreen-ui-1l06pbn">
encryptedFields
</code>
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create New Documents Operation Using
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#create-new-documents-operation-using--densify" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-new-documents-operation-using--densify">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your application uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/densify/#mongodb-pipeline-pipe.-densify">
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</a>
to create documents that
fill gaps, add missing values, or populate your data with specified
range of values, remove the
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
stage from your aggregation
pipeline before downgrading. The
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
stage is only available in
version 5.1 and later.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/js-atlas-streams/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Atlas Stream Processing Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#atlas-stream-processing-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="atlas-stream-processing-methods">
</div>
</a>
</h1>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Methods
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The methods listed on this table of contents page are
<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. This is
<em>
not
</em>
the documentation for
<code class="leafygreen-ui-1l06pbn">
Node.js
</code>
or other programming language specific driver methods.
</p>
<p class="leafygreen-ui-1kp3ins">
In most cases,
<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 work the same way as the
legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell methods. However, some legacy methods
are unavailable in
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
.
</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
</span>
</a>
documentation.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-sp/overview/#mongodb-expression-exp.Stream-Processor" target="_self">
<span>
Atlas Stream Processors
</span>
</a>
let you perform aggregation operations against streams of
continuous data using the same data model and query API that
you use with at-rest data.
</p>
<p class="leafygreen-ui-1kp3ins">
Use the following methods to manage Stream Processors
</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 following methods can only be run on deployments hosted on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self">
<span>
MongoDB Atlas
<!-- -->
.
</span>
</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">
For details on a specific method, including syntax and examples,
click on the link to the method's reference page.
</p>
</div>
</div>
<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>
Name
</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/method/sp.createStreamProcessor/#mongodb-method-sp.createStreamProcessor">
<code class="leafygreen-ui-1l06pbn">
sp.createStreamProcessor()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Creates a stream processor.
</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/sp.listStreamProcessors/#mongodb-method-sp.listStreamProcessors">
<code class="leafygreen-ui-1l06pbn">
sp.listStreamProcessors()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lists all existing stream processors on the current stream
processing instance.
</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/sp.process/#mongodb-method-sp.process">
<code class="leafygreen-ui-1l06pbn">
sp.process()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Creates an ephemeral stream processor.
</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/sp.processor.drop/#mongodb-method-sp.processor.drop">
<code class="leafygreen-ui-1l06pbn">
sp.processor.drop()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Deletes an existing stream processor.
</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/sp.processor.sample/#mongodb-method-sp.processor.sample">
<code class="leafygreen-ui-1l06pbn">
sp.processor.sample()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns an array of sampled results from a currently running stream processor.
</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/sp.processor.start/#mongodb-method-sp.processor.start">
<code class="leafygreen-ui-1l06pbn">
sp.processor.start()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Starts an existing stream processor.
</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/sp.processor.stats/#mongodb-method-sp.processor.stats">
<code class="leafygreen-ui-1l06pbn">
sp.processor.stats()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns statistics summarizing an existing stream processor.
</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/sp.processor.stop/#mongodb-method-sp.processor.stop">
<code class="leafygreen-ui-1l06pbn">
sp.processor.stop()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Stops a currently running stream processor.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
|
https://www.mongodb.com/docs/manual/core/sharding-shard-key/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" 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>
</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="#shard-key-indexes" target="_self">
<span>
Shard Key Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#missing-shard-key-fields" target="_self">
<span>
Missing Shard Key Fields
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The shard key is either a single indexed
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-field">
field
</a>
or multiple
fields covered by a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
compound index
</a>
that determines the
distribution of the collection's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-document">
documents
</a>
among the
cluster's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shards
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB divides the span of shard key values (or hashed
shard key values) into non-overlapping ranges of shard key values (or
hashed shard key values). Each range is associated with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunk
</a>
, and MongoDB attempts to distribute chunks evenly among
the shards in the cluster.
</p>
<div class="figure css-5vkxs0" style="width:700px">
<img alt="Diagram of the shard key value space segmented into smaller ranges or chunks." class="leafygreen-ui-1qnf57e" height="250" src="/docs/manual/images/sharding-range-based.bakedsvg.svg" style="--border-color:#C1C7C6" width="760"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The shard key has a direct relationship to the effectiveness of chunk
distribution. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection">
Choose a Shard Key
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-internals-shard-key-indexes">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-shard-key-indexes">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Shard Key Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-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="shard-key-indexes">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
All sharded collections
<strong>
must
</strong>
have an index that supports the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
. The index can be an index on the shard key or a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
compound index
</a>
where the shard key is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-compound-index-prefix">
prefix
</a>
of the index.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the collection is empty,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
creates
the index on the shard key if such an index does not already exists.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the collection is not empty, you must create the index first
before using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You cannot
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dropIndex/#std-label-collection-drop-index">
drop
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.hideIndex/#std-label-collection-hide-index">
hide
</a>
an index if it is the only
non-hidden index that supports the shard key.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-shard-key-unique">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unique Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#unique-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="unique-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB can enforce a uniqueness constraint on a ranged shard key index.
Through the use of a unique index on the shard key, MongoDB enforces
uniqueness on the entire key combination and not individual components
of the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
For a ranged sharded collection, only the following indexes can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The index on the shard key
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
compound index
</a>
where the shard key is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-compound-index-prefix">
prefix
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The default
<code class="leafygreen-ui-1l06pbn">
_id
</code>
index.
</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">
Sharded clusters only enforce the uniqueness constraint on
<code class="leafygreen-ui-1l06pbn">
_id
</code>
fields across the cluster when the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is
also the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is not the shard key or if it is only
the prefix to the shard key, the uniqueness constraint
applies only to the shard that stores the document. This
means that two or more documents can have the same
<code class="leafygreen-ui-1l06pbn">
_id
</code>
value, provided they occur on different shards.
</p>
<p class="leafygreen-ui-1kp3ins">
In cases where the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is not the shard key,
MongoDB expects applications to enforce the uniqueness of
<code class="leafygreen-ui-1l06pbn">
_id
</code>
values across the shards.
</p>
</div>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The unique index constraints mean that:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For a to-be-sharded collection, you cannot shard the collection if
the collection has other unique indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For an already-sharded collection, you cannot create unique indexes
on other fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A unique index stores a null value for a document missing the
indexed field; that is a missing index field is treated as another
instance of a
<code class="leafygreen-ui-1l06pbn">
null
</code>
index key value. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-unique-index-and-missing-field">
Missing Document Field in a Unique Single-Field Index
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To enforce uniqueness on the shard key values, pass the
<code class="leafygreen-ui-1l06pbn">
unique
</code>
parameter as
<code class="leafygreen-ui-1l06pbn">
true
</code>
to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
method:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the collection is empty,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
creates the unique index on the
shard key if such an index does not already exist.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the collection is not empty, you must create the index first
before using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Although you can have a unique
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-compound-index">
compound index
</a>
where the shard
key is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-compound-index-prefix">
prefix
</a>
, if using
<code class="leafygreen-ui-1l06pbn">
unique
</code>
parameter, the collection must have a unique index that is on the shard
key.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot specify a unique constraint on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/#std-label-index-type-hashed">
hashed index
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To maintain uniqueness on a field that is not your shard key,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/unique-constraints-on-arbitrary-fields/#std-label-shard-key-arbitrary-uniqueness">
Unique Constraints on Arbitrary Fields
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-shard-key-missing">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Missing Shard Key Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#missing-shard-key-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="missing-shard-key-fields">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Documents in sharded collections can be missing the shard key fields.
To set missing shard key fields, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-set-missing-shard-key-fields/#std-label-shard-key-missing-set">
Set Missing Shard Key Fields
<!-- -->
.
</a>
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Chunk Range and Missing Shard Key Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#chunk-range-and-missing-shard-key-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="chunk-range-and-missing-shard-key-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Missing shard key fields fall within the same chunk range as shard keys
with null values. For example, if the shard key is on the fields
<code class="leafygreen-ui-1l06pbn">
{ x:
1, y: 1 }
</code>
, then:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:60%"/>
<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>
Document Missing Shard Key
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Falls into Same Range As
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ x: "hello" }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ x: "hello", y: null }
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ y: "goodbye" }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ x: null, y: "goodbye" }
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ z: "oops" }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ x: null, y: null }
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-shard-key-missing-read-write-ops">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Read/Write Operations and Missing Shard Key Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#read-write-operations-and-missing-shard-key-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="read-write-operations-and-missing-shard-key-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To target documents with missing shard key fields, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/exists/#mongodb-query-op.-exists">
<code class="leafygreen-ui-1l06pbn">
{ $exists: false }
</code>
</a>
filter condition on the shard key
fields. For example, if the shard key is on the fields
<code class="leafygreen-ui-1l06pbn">
{ x: 1, y: 1
}
</code>
, you can find the documents with missing shard key fields by running
this query:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shardedcollection.find( { $or: [ { x: { $exists: false } }, { y: { $exists: false } } ] } )","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">shardedcollection</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">$or</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">x</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">false</span> } }<!-- -->, <!-- -->{ <span class="lg-highlight-attr">y</span>: <!-- -->{ <span class="lg-highlight-attr">$exists</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>
<p class="leafygreen-ui-1kp3ins">
If you specify a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/query-for-null-fields/">
null equality match
</a>
filter condition (e.g.
<code class="leafygreen-ui-1l06pbn">
{ x: null
}
</code>
), the filter matches
<strong class="css-4dei7l">
both
</strong>
those documents with missing shard
key fields
<strong class="css-4dei7l">
and
</strong>
those with shard key fields set to
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Some write operations, such as a write with an
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
specification, require an equality match on the shard key. In those
cases, to target a document that is missing the shard key, include
another filter condition in addition to the
<code class="leafygreen-ui-1l06pbn">
null
</code>
equality match.
For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: <value>, <shardkeyfield>: null } // _id of the document missing shard key","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">_id</span>: <<!-- -->value<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->shardkeyfield<!-- -->><!-- -->: <span class="lg-highlight-literal">null</span> } <span class="lg-highlight-comment">// _id of</span><span class="lg-highlight-comment"> the document missing </span><span class="lg-highlight-comment">shard key</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/core/sharding-troubleshooting-shard-keys/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Troubleshoot Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#troubleshoot-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="troubleshoot-shard-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="#jumbo-chunks" target="_self">
<span>
Jumbo Chunks
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uneven-load-distribution" target="_self">
<span>
Uneven Load Distribution
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#decreased-query-performance-over-time" target="_self">
<span>
Decreased Query Performance Over Time
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The ideal shard key allows MongoDB to distribute documents evenly
throughout the cluster while facilitating common query patterns. A
suboptimal shard key can lead to the following problems:
</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-sharding-troubleshooting-jumbo-chunks" target="_self">
<span>
Jumbo chunks
</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-sharding-troubleshooting-monotonicity" target="_self">
<span>
Uneven load distribution
</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-sharding-troubleshooting-scatter-gather" target="_self">
<span>
Decreased query performance over time
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
In the following you can find out more about common problems with shard
keys and how to resolve them.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-jumbo-chunks">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Jumbo Chunks
<a class="headerlink leafygreen-ui-1kepx47" href="#jumbo-chunks" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="jumbo-chunks">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you are seeing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-jumbo-chunks">
jumbo chunks
</a>
, either the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-cardinality">
cardinality
</a>
of your shard key is
insufficient or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-frequency">
frequency
</a>
of the shard
key values is unevenly distributed.
</p>
<p class="leafygreen-ui-1kp3ins">
To increase the cardinality of your shard key or change the distribution
of your shard key values, you can:
</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/sharding-refine-a-shard-key/#std-label-shard-key-refine">
refine your shard key
</a>
by adding a suffix
field or fields to the existing key to increase cardinality
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
reshard your collection
</a>
using a
different shard key with higher cardinality
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To learn whether you should reshard your collection
or refine your shard key, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-change-a-shard-key/#std-label-change-a-shard-key">
Change a Shard Key
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To only change the distribution of your shard key values, you can also
consider using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
Hashed Sharding
</a>
to distribute your data more
evenly.
</p>
<p class="leafygreen-ui-1kp3ins">
For advice on choosing a shard key see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection">
Choose a Shard Key
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-monotonicity">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Uneven Load Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#uneven-load-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="uneven-load-distribution">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If your cluster is experiencing uneven load distribution, check if your
shard key increases
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-monotonic">
monotonically
</a>
. A shard
key that is a monotonically increasing field, leads to an uneven read
and write distribution.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider an
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection that is sharded on an
<code class="leafygreen-ui-1l06pbn">
order_id
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
order_id
</code>
is an integer which increases by one with each
order.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-shard-hotness">
</span>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
New documents are generally written to the same shard and chunk. The
shard and chunk that receive the writes are called
<em>
hot
</em>
shard and
<em>
hot
</em>
chunk. The
<em>
hot
</em>
shard changes over time. When chunks are split,
the hot chunk moves to a different shard to optimize data
distribution.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If users are more likely to interact with recent orders, which are all
on the same shard, the shard that contains recent orders will receive
most of the traffic.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you have a monotonically increasing shard key, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
resharding your collection
</a>
. For advice on
choosing a shard key see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection">
Choose a Shard Key
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If your data model requires sharding on a key that changes
monotonically, consider using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
Hashed Sharding
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-troubleshooting-scatter-gather">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Decreased Query Performance Over Time
<a class="headerlink leafygreen-ui-1kepx47" href="#decreased-query-performance-over-time" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="decreased-query-performance-over-time">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
If you are noticing decreased query performance over time, it is
possible that your cluster is performing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-query-patterns">
scatter-gather queries
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To evaluate if your cluster is performing scatter-gather queries, check
if your most common queries include the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
If you include the shard key in your queries, check if your shard key is
hashed. With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/hashed-sharding/">
Hashed Sharding
</a>
, documents are not stored in
ascending or descending order of the shard key field value. Performing
range based queries on the shard key value on data that is not stored in
ascending or descending order results in less performant scatter-gather
queries. If range based queries on your shard key are a common access
pattern, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
resharding your collection
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you do not include the shard key in your most common queries, it is
possible that you could increase performance by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-sharding-resharding">
resharding your
collection
</a>
. For advice on choosing a shard key
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-selection">
Choose a Shard Key
<!-- -->
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$substr (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-substr--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="-substr--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">
$substr
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-substr" 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.-substr">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
Deprecated
<!-- -->
since version
<!-- -->
3.4
</em>
:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/substr/#mongodb-expression-exp.-substr">
<code class="leafygreen-ui-1l06pbn">
$substr
</code>
</a>
is now an alias for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/substrBytes/#mongodb-expression-exp.-substrBytes">
<code class="leafygreen-ui-1l06pbn">
$substrBytes
</code>
.
</a>
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns a substring of a string, starting at a specified index
position and including the specified number of characters. The index
is zero-based.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-substr" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$substr
</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":"{ $substr: [ <string>, <start>, <length> ] }","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">$substr</span>: <!-- -->[ <<!-- -->string<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->start<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->length<!-- -->> <!-- -->] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 the first argument
resolves to a string, and the second and third arguments resolve to
integers. 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
<code class="leafygreen-ui-1l06pbn">
<start>
</code>
is a negative number,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-substr" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$substr
</code>
</span>
</a>
returns an
empty string
<code class="leafygreen-ui-1l06pbn">
""
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
<length>
</code>
is a negative number,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-substr" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$substr
</code>
</span>
</a>
returns a
substring that starts at the specified index and includes the rest of
the string.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-substr" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$substr
</code>
</span>
</a>
only has
<!-- -->
a well-defined behavior for strings of ASCII characters.
</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 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\" : \"ABC1\", quarter: \"13Q1\", \"description\" : \"product 1\" }\n{ \"_id\" : 2, \"item\" : \"ABC2\", quarter: \"13Q4\", \"description\" : \"product 2\" }\n{ \"_id\" : 3, \"item\" : \"XYZ1\", quarter: \"14Q2\", \"description\" : null }","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">quarter</span>: <span class="lg-highlight-string">"13Q1"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 1"</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">quarter</span>: <span class="lg-highlight-string">"13Q4"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 2"</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">"XYZ1"</span>, <span class="lg-highlight-attr">quarter</span>: <span class="lg-highlight-string">"14Q2"</span>, <span class="lg-highlight-string">"description"</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>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-substr" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$substr
</code>
</span>
</a>
operator
to separate the
<code class="leafygreen-ui-1l06pbn">
quarter
</code>
value into a
<code class="leafygreen-ui-1l06pbn">
yearSubstring
</code>
and a
<code class="leafygreen-ui-1l06pbn">
quarterSubstring
</code>
:
</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 item: 1,\n yearSubstring: { $substr: [ \"$quarter\", 0, 2 ] },\n quarterSubtring: { $substr: [ \"$quarter\", 2, -1 ] }\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">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">yearSubstring</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$quarter"</span>, <span class="lg-highlight-number">0</span>, <span class="lg-highlight-number">2</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">quarterSubtring</span>: <!-- -->{ <span class="lg-highlight-attr">$substr</span>: <!-- -->[ <span class="lg-highlight-string">"$quarter"</span>, <span class="lg-highlight-number">2</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"> ]</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, \"item\" : \"ABC1\", \"yearSubstring\" : \"13\", \"quarterSubtring\" : \"Q1\" }\n{ \"_id\" : 2, \"item\" : \"ABC2\", \"yearSubstring\" : \"13\", \"quarterSubtring\" : \"Q4\" }\n{ \"_id\" : 3, \"item\" : \"XYZ1\", \"yearSubstring\" : \"14\", \"quarterSubtring\" : \"Q2\" }","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">"yearSubstring"</span> <!-- -->: <span class="lg-highlight-string">"13"</span>, <span class="lg-highlight-string">"quarterSubtring"</span> <!-- -->: <span class="lg-highlight-string">"Q1"</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">"yearSubstring"</span> <!-- -->: <span class="lg-highlight-string">"13"</span>, <span class="lg-highlight-string">"quarterSubtring"</span> <!-- -->: <span class="lg-highlight-string">"Q4"</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">"XYZ1"</span>, <span class="lg-highlight-string">"yearSubstring"</span> <!-- -->: <span class="lg-highlight-string">"14"</span>, <span class="lg-highlight-string">"quarterSubtring"</span> <!-- -->: <span class="lg-highlight-string">"Q2"</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/release-notes/7.0/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Release Notes for MongoDB 7.0 (Stable Release)
<a class="headerlink leafygreen-ui-1kepx47" href="#release-notes-for-mongodb-7.0--stable-release-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="release-notes-for-mongodb-7.0--stable-release-">
</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="#patch-releases" target="_self">
<span>
Patch Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#atlas-search-index-management" target="_self">
<span>
Atlas Search Index Management
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#general-changes" target="_self">
<span>
General Changes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#security" target="_self">
<span>
Security
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#aggregation" target="_self">
<span>
Aggregation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#time-series" target="_self">
<span>
Time Series
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharding" target="_self">
<span>
Sharding
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#changes-introduced-in-6.x-series-rapid-releases" target="_self">
<span>
Changes Introduced in 6.X-Series Rapid Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#platform-support" target="_self">
<span>
Platform Support
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#upgrade-procedures" target="_self">
<span>
Upgrade Procedures
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#downgrade-considerations" target="_self">
<span>
Downgrade Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#download" target="_self">
<span>
Download
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#report-an-issue" target="_self">
<span>
Report an Issue
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page describes changes and new features introduced in MongoDB 7.0.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 is a
<!-- -->
Major
<!-- -->
Release, which means that it is supported for
both MongoDB Atlas and on-premises deployments. MongoDB 7.0 includes
changes introduced in MongoDB Rapid Releases 6.1, 6.2, and 6.3. To see
changes introduced in these rapid releases, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-7.0-rapid-release-changes" target="_self">
<span>
Changes Introduced in 6.X-Series Rapid Releases
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about the differences between
<!-- -->
Major
<!-- -->
and Rapid releases,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-release-version-numbers">
MongoDB Versioning
<!-- -->
.
</a>
</p>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Past Release Limitations
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The Critical Advisories below affect some prior MongoDB versions. If your
deployment depends on features impacted by a Critical Advisory, upgrade to
the latest available patch release.
</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>
Issue
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Affected Versions
</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="https://jira.mongodb.org/browse/SERVER-77506" rel="noopener noreferrer">
<span>
SERVER-77506
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0.0 - 7.0.2
</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="https://jira.mongodb.org/browse/SERVER-80203" rel="noopener noreferrer">
<span>
SERVER-80203
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0.0 - 7.0.2 (Time Series collections sharded by metaField embedded
objects)
</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="https://jira.mongodb.org/browse/SERVER-82353" rel="noopener noreferrer">
<span>
SERVER-82353
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0.0 - 7.0.5
</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="https://jira.mongodb.org/browse/SERVER-84723" rel="noopener noreferrer">
<span>
SERVER-84723
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0.0 - 7.0.6
</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="https://jira.mongodb.org/browse/SERVER-87061" rel="noopener noreferrer">
<span>
SERVER-87061
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0.0 - 7.0.6
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Patch Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#patch-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="patch-releases">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.14-release-notes">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.14 - Aug 26, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.14---aug-26--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.14---aug-26--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues Fixed:
</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://jira.mongodb.org/browse/SERVER-82814" rel="noopener noreferrer">
<span>
SERVER-82814
</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>
Support internal expr comparison operators when
determining clustered collection scan bounds
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-85892" rel="noopener noreferrer">
<span>
SERVER-85892
</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>
$merge with pipeline after $documents returns
error
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-91195" rel="noopener noreferrer">
<span>
SERVER-91195
</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>
Provide a generic backportable solution not to
miss top-level timeseries collection options
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-91625" rel="noopener noreferrer">
<span>
SERVER-91625
</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>
Enable indexed plans for expressions with $$NOW,
$$CLUSTER_TIME and $$USER_ROLES
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-12643" rel="noopener noreferrer">
<span>
WT-12643
</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>
Fix Eviction Server walk logic so that it's able to
evict all pages
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-13109?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20(fixversion%3D7.0.13%20or%20fixversion%20%3D%207.0.14)" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.14
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.14-changelog">
7.0.14 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.12-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.12 - Jun 28, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.12---jun-28--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.12---jun-28--2024">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Fix for CSFLE and Queryable Encryption self-lookup may send values in subpipelines as plaintext instead of ciphertext
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Due to CVE-2024-8013, in
<!-- -->
MongoDB 7.0 prior to 7.0.12
<!-- -->
, a bug in query analysis of
certain complex self-referential
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
subpipelines
may result in literal values in expressions for encrypted fields
being sent to the server malformed.
</p>
<p class="leafygreen-ui-1kp3ins">
Should this occur, no documents are returned or written.
This issue affects the
<code class="leafygreen-ui-1l06pbn">
mongocryptd
</code>
binary and
<code class="leafygreen-ui-1l06pbn">
mongo_crypt_v1
</code>
shared library in the following MongoDB Server versions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
7.3.0 - 7.3.3
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
7.0.0 - 7.0.11
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
6.0.0 - 6.0.16
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
5.0.0 - 5.0.28
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<strong>
CVSS Score
</strong>
: 2.2
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
CWE
</strong>
: CWE-319: Cleartext Transmission of Sensitive Information
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Issues Fixed:
</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://jira.mongodb.org/browse/SERVER-96254" rel="noopener noreferrer">
<span>
SERVER-96254
</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>
CSFLE and Queryable Encryption self-lookup may
fail to encrypt values in subpipelines
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-64574" rel="noopener noreferrer">
<span>
SERVER-64574
</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>
Upgrade MozJS/Spidermonkey to the latest ESR
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-86674" rel="noopener noreferrer">
<span>
SERVER-86674
</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>
Primary catch-up may believe it is caught up when it
is not
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-90485" rel="noopener noreferrer">
<span>
SERVER-90485
</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>
$sort does not work as expected when used in
conjunction with includeArrayIndex
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-91362" rel="noopener noreferrer">
<span>
SERVER-91362
</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>
Performance: Do not copy JS "scope" object if a
cached JsExecution exists
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-12736" rel="noopener noreferrer">
<span>
WT-12736
</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>
Mark the page clean after re-instantiating the page with
prepared updates
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D7.0.12" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.12
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.12-changelog">
7.0.12 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.11-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.11 - May 23, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.11---may-23--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.11---may-23--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues Fixed:
</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://jira.mongodb.org/browse/SERVER-85279" rel="noopener noreferrer">
<span>
SERVER-85279
</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>
Don't run the FTDC collection stats
collector on arbiters
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-89495" rel="noopener noreferrer">
<span>
SERVER-89495
</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>
Disable test parameters even when no
setParameters are specified
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-89625" rel="noopener noreferrer">
<span>
SERVER-89625
</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>
Handle directoryPerDb and
wiredTigerDirectoryForIndexes correctly when reporting
namespaces and UUIDs during a backup
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-90288" rel="noopener noreferrer">
<span>
SERVER-90288
</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>
Bitwise query operators should interpret
lowest addressable byte in BinData as least significant byte
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-12609" rel="noopener noreferrer">
<span>
WT-12609
</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>
Improve checkpoint cleanup and page eviction
logic
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D7.0.11" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.11
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.11-changelog">
7.0.11 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.9-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.9 - Apr 26, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.9---apr-26--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.9---apr-26--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-79637" rel="noopener noreferrer">
<span>
SERVER-79637
</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>
Incorrect query results in $lookup with TS foreign collection
using a correlated predicate
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-82349" rel="noopener noreferrer">
<span>
SERVER-82349
</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>
Mongo 7 crashes on applyOps index delete/drops without a collection UUID
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-86407" rel="noopener noreferrer">
<span>
SERVER-86407
</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>
Validation does not produce complete results when it should
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-88173" rel="noopener noreferrer">
<span>
SERVER-88173
</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>
BinData bit comparisons give wrong results in many cases
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-10807" rel="noopener noreferrer">
<span>
WT-10807
</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>
Skip in-memory deleted pages as part of the tree walk
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D7.0.9" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.9
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.9-changelog">
7.0.9 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.8-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.8 - Apr 3, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.8---apr-3--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.8---apr-3--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-78556" rel="noopener noreferrer">
<span>
SERVER-78556
</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>
Return default of internalInsertMaxBatchSize to 64
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79575" rel="noopener noreferrer">
<span>
SERVER-79575
</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>
Fix numa node counting
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-86583" rel="noopener noreferrer">
<span>
SERVER-86583
</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>
Non-transactional snapshot read on unsharded collection
may execute with mismatched sharding metadata
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-87666" rel="noopener noreferrer">
<span>
SERVER-87666
</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>
Query shape for $documents is unique on each execution
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-88360" rel="noopener noreferrer">
<span>
SERVER-88360
</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>
Remove "Sharding catalog and local catalog collection
uuid do not match" tripwire assertion
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D7.0.8" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.8
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.8-changelog">
7.0.8 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.7-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.7 - Mar 18, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.7---mar-18--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.7---mar-18--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-84368" rel="noopener noreferrer">
<span>
SERVER-84368
</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>
CreateIndex fails with StaleConfig if run from a
stale mongos against a sharded non-empty collection
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-84628" rel="noopener noreferrer">
<span>
SERVER-84628
</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>
Startup warning in mongos for Read/Write Concern
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-85459" rel="noopener noreferrer">
<span>
SERVER-85459
</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>
[v7.0] bucketRoundingSeconds param is accepted
by nodes on fCV 6.0, binary 7.0
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-85869" rel="noopener noreferrer">
<span>
SERVER-85869
</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>
Exhaustive find on config shard can return stale
data
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-87061" rel="noopener noreferrer">
<span>
SERVER-87061
</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>
Sharded multi-document transactions can observe
partial effects of concurrent reshard operation
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.7%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.7
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.7-changelog">
7.0.7 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.6-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.6 - Feb 28, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.6---feb-28--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.6---feb-28--2024">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Fix for MongoDB Server may allow successful untrusted connection
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Due to CVE-2024-1351, in
<!-- -->
MongoDB 7.0 prior to 7.0.6
<!-- -->
, under certain
configurations of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCAFile">
<code class="leafygreen-ui-1l06pbn">
--tlsCAFile
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.CAFile">
<code class="leafygreen-ui-1l06pbn">
CAFile
</code>
</a>
, MongoDB Server may skip peer certificate
validation which may result in untrusted connections to succeed.
</p>
<p class="leafygreen-ui-1kp3ins">
This may effectively reduce the security guarantees provided by TLS
and open connections that should have been closed due to failing
certificate validation. This issue affects the following MongoDB
Server versions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
7.0.0 - 7.0.5
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
6.0.0 - 6.0.13
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
5.0.0 - 5.0.24
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
4.4.0 - 4.4.28
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<strong>
CVSS Score
</strong>
: 8.8
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
CWE
</strong>
: CWE-295: Improper Certificate Validation
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-72703" rel="noopener noreferrer">
<span>
SERVER-72703
</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>
Downgrade $out's db lock to MODE_IX
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-82353" rel="noopener noreferrer">
<span>
SERVER-82353
</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>
Multi-document transactions can miss documents
when movePrimary runs concurrently
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-84338" rel="noopener noreferrer">
<span>
SERVER-84338
</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>
Top level $or queries may lead to invalid SBE
plan cache entry which returns wrong results
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-84723" rel="noopener noreferrer">
<span>
SERVER-84723
</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>
Sharded multi-document transactions can observe
partial effects of concurrent DDL operations
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-11062" rel="noopener noreferrer">
<span>
WT-11062
</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>
Safe free the ref addr to allow concurrent access
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.6%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.6
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.6-changelog">
7.0.6 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.5-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.5 - Jan 5, 2024
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.5---jan-5--2024" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="7.0.5---jan-5--2024">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-33494" rel="noopener noreferrer">
<span>
SERVER-33494
</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>
WT SizeStorer never deletes old entries
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-80363" rel="noopener noreferrer">
<span>
SERVER-80363
</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>
server default writeConcern is not honored when
wtimeout is set
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-83091" rel="noopener noreferrer">
<span>
SERVER-83091
</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 query can trigger an infinite loop during
plan enumeration
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-83830" rel="noopener noreferrer">
<span>
SERVER-83830
</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>
On Enterprise build creating a collection in a
replica set with the storageEngine.inMemory option breaks secondaries
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-7929" rel="noopener noreferrer">
<span>
WT-7929
</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>
Investigate a solution to avoid FTDC stalls during
checkpoint
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.5%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.5
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.5-changelog">
7.0.5 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.4-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.4 - Nov 27, 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.4---nov-27--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="7.0.4---nov-27--2023">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-67962" rel="noopener noreferrer">
<span>
SERVER-67962
</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>
Applying config.image_collection deletes needs
better concurrency control
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-69244" rel="noopener noreferrer">
<span>
SERVER-69244
</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>
$merge fails when session default read concern
has been set to "majority"
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79975" rel="noopener noreferrer">
<span>
SERVER-79975
</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>
[Classic] Optimize large group keys
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-81133" rel="noopener noreferrer">
<span>
SERVER-81133
</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>
Speedup logic to persist routing table cache
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-82446" rel="noopener noreferrer">
<span>
SERVER-82446
</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>
$densify use case can result in documents
outside of range
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.4%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.4
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.4-changelog">
7.0.4 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.3-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.3 - Nov 9, 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.3---nov-9--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="7.0.3---nov-9--2023">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-77506" rel="noopener noreferrer">
<span>
SERVER-77506
</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>
Sharded multi-document transactions can
mismatch data and ShardVersion
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79088" rel="noopener noreferrer">
<span>
SERVER-79088
</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>
Improve SBE
multi-planner performance for query which returns zero results
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-81106" rel="noopener noreferrer">
<span>
SERVER-81106
</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>
Recipient shard doesn't wait for the collection
version to be locally persisted before starting the cloning phase
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-81966" rel="noopener noreferrer">
<span>
SERVER-81966
</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>
Avoid modification of previous ChunkMap instances
during refresh
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/WT-11564" rel="noopener noreferrer">
<span>
WT-11564
</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>
Fix RTS to read the newest
transaction value only when it exists in the checkpoint
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.3%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.3
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.3-changelog">
7.0.3 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.2-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.2 - Sep 29, 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.2---sep-29--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="7.0.2---sep-29--2023">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-74954" rel="noopener noreferrer">
<span>
SERVER-74954
</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>
Incorrect result when contained $or rewrites $elemMatch
extra condition
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79771" rel="noopener noreferrer">
<span>
SERVER-79771
</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>
Make Resharding Operation Resilient to
NetworkInterfaceExceededTimeLimit
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79912" rel="noopener noreferrer">
<span>
SERVER-79912
</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>
CheckReplDBHash reports failure with system.buckets
collections due to invalid BSON
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-79982" rel="noopener noreferrer">
<span>
SERVER-79982
</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>
Batched catalog writers can run concurrently with
HistoricalCatalogIdTracker::cleanup() and lead to incorrect PIT find results
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-80488" rel="noopener noreferrer">
<span>
SERVER-80488
</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>
Avoid traversing routing table in balancer split chunk
policy
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.2%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.2
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.2-changelog">
7.0.2 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.1-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.1 - Sep 5, 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.1---sep-5--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="7.0.1---sep-5--2023">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Issues fixed:
</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://jira.mongodb.org/browse/SERVER-71627" rel="noopener noreferrer">
<span>
SERVER-71627
</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>
Refreshing cached collection route info severely
blocks all client requests for a cluster with 1 million chunks
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-77183" rel="noopener noreferrer">
<span>
SERVER-77183
</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>
$project followed by $group sometimes gives incorrect
results
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER-80256" rel="noopener noreferrer">
<span>
SERVER-80256
</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>
QueryPlannerAnalysis::explodeForSort should not assume
that index scans produce disjoint results
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/issues/?jql=project%20in%20(SERVER%2CTOOLS%2CWT)%20AND%20resolution%3D%27Fixed%27%20and%20fixversion%3D%277.0.1%27" rel="noopener noreferrer">
<span>
All Jira issues closed in 7.0.1
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-changelog/#std-label-7.0.1-changelog">
7.0.1 Changelog
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0.0-release-notes">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
7.0.0 - Aug 15, 2023
<a class="headerlink leafygreen-ui-1kepx47" href="#7.0.0---aug-15--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="7.0.0---aug-15--2023">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The rest of this page describes changes and new features introduced in MongoDB
7.0.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Atlas Search Index Management
<a class="headerlink leafygreen-ui-1kepx47" href="#atlas-search-index-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="atlas-search-index-management">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can manage
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self">
<span>
Atlas Search indexes
</span>
</a>
with
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
methods and database commands. Atlas Search index commands are only available
for deployments hosted on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self">
<span>
MongoDB Atlas
</span>
</a>
, and require an
Atlas cluster tier of at least M10.
</p>
<p class="leafygreen-ui-1kp3ins">
To manage Atlas Search indexes, use the following commands:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
mongosh Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#mongosh-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="mongosh-methods">
</div>
</a>
</h3>
<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>
Name
</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/method/db.collection.createSearchIndex/#mongodb-method-db.collection.createSearchIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createSearchIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Creates an
<!-- -->
Atlas Search index
<!-- -->
on a specified collection.
</p>
</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.dropSearchIndex/#mongodb-method-db.collection.dropSearchIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.dropSearchIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Deletes an existing
<!-- -->
Atlas Search index
<!-- -->
.
</p>
</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.getSearchIndexes/#mongodb-method-db.collection.getSearchIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.getSearchIndexes()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Returns information about existing
<!-- -->
Atlas Search indexes
<!-- -->
on a specified
collection.
</p>
</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.updateSearchIndex/#mongodb-method-db.collection.updateSearchIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.updateSearchIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Updates an existing
<!-- -->
Atlas Search index
<!-- -->
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Database Commands
<a class="headerlink leafygreen-ui-1kepx47" href="#database-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="database-commands">
</div>
</a>
</h3>
<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>
Name
</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/command/createSearchIndexes/#mongodb-dbcommand-dbcmd.createSearchIndexes">
<code class="leafygreen-ui-1l06pbn">
createSearchIndexes
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Creates one or more
<!-- -->
Atlas Search indexes
<!-- -->
on a specified collection.
</p>
</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/command/dropSearchIndex/#mongodb-dbcommand-dbcmd.dropSearchIndex">
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Deletes an existing
<!-- -->
Atlas Search index
<!-- -->
.
</p>
</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/command/updateSearchIndex/#mongodb-dbcommand-dbcmd.updateSearchIndex">
<code class="leafygreen-ui-1l06pbn">
updateSearchIndex
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Updates an existing
<!-- -->
Atlas Search index
<!-- -->
.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Aggregation Stages
<a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-stages" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="aggregation-stages">
</div>
</a>
</h3>
<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>
Name
</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/aggregation/listSampledQueries/#mongodb-pipeline-pipe.-listSampledQueries">
<code class="leafygreen-ui-1l06pbn">
$listSampledQueries
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lists sampled queries for all collections or a specific
collection.
</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/aggregation/listSearchIndexes/#mongodb-pipeline-pipe.-listSearchIndexes">
<code class="leafygreen-ui-1l06pbn">
$listSearchIndexes
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Returns information about existing
<!-- -->
Atlas Search indexes
<!-- -->
on a specified
collection.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
General Changes
<a class="headerlink leafygreen-ui-1kepx47" href="#general-changes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="general-changes">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
OIDC Access Token Authentication Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#oidc-access-token-authentication-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="oidc-access-token-authentication-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, only one
<code class="leafygreen-ui-1l06pbn">
audience
</code>
oidcIdentityProviders
field can be specified for OIDC access tokens.
<code class="leafygreen-ui-1l06pbn">
audience
</code>
fields
with empty arrays or arrays of multiple strings are invalid.
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#std-label-oidcidentityproviders-fields">
oidcIdentityProviders Fields
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Drop a Hashed Shard Key Index
<a class="headerlink leafygreen-ui-1kepx47" href="#drop-a-hashed-shard-key-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="drop-a-hashed-shard-key-index">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0.3 (and 6.0.12 and 5.0.22), you can drop the
index for a hashed shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
This can speed up data insertion for collections sharded with a hashed
shard key. It can also speed up data ingestion when using
<code class="leafygreen-ui-1l06pbn">
mongosync
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/drop-a-hashed-shard-key-index/#std-label-drop-a-hashed-shard-key-index">
Drop a Hashed Shard Key Index
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Cache Refresh Time Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#cache-refresh-time-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="cache-refresh-time-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-slow-ops">
log messages for slow queries
</a>
includes a new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-cache-refresh-times">
cache refresh time field
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Concurrent Storage Engine Transactions (Read and Write Tickets)
<a class="headerlink leafygreen-ui-1kepx47" href="#concurrent-storage-engine-transactions--read-and-write-tickets-" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="concurrent-storage-engine-transactions--read-and-write-tickets-">
</div>
</a>
</h3>
<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
(including both read and write tickets) to optimize database throughput
during overload.
</p>
<p class="leafygreen-ui-1kp3ins">
The following table summarizes how to identify overload scenarios for MongoDB
post-7.0 and for earlier releases:
</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>
Version
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Diagnosing Overload Scenarios
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
7.0 and later
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A large number of queued operations that persists for a
prolonged period of time likely indicates an overload.
</p>
<p class="leafygreen-ui-1kp3ins">
A concurrent storage engine transaction (ticket) availibility of
0 for a prolonged period of time
<strong>
does not
</strong>
indicate an overload.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
6.0 and earlier
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
A large number of queued operations that persists for a
prolonged period of time likely indicates an overload.
</p>
<p class="leafygreen-ui-1kp3ins">
A concurrent storage engine transaction (ticket) availibility of
0 for a prolonged period of time likely indicates an overload.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<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">
<code class="leafygreen-ui-1l06pbn">
wiredTiger.concurrentTransactions
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Renamed
<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>
in v8.0.
</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.storageEngineConcurrentReadTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentReadTransactions
</code>
</a>
</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.storageEngineConcurrentWriteTransactions">
<code class="leafygreen-ui-1l06pbn">
storageEngineConcurrentWriteTransactions
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
Metrics
<a class="headerlink leafygreen-ui-1kepx47" href="#currentop-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="currentop-metrics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/currentOp/#mongodb-dbcommand-dbcmd.currentOp">
<code class="leafygreen-ui-1l06pbn">
currentOp
</code>
</a>
command and the
<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>
method include these new fields:
</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/currentOp/#mongodb-data-currentOp.admissionPriority">
<code class="leafygreen-ui-1l06pbn">
currentOp.admissionPriority
</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/#mongodb-data-currentOp.collUuid">
<code class="leafygreen-ui-1l06pbn">
currentOp.collUuid
</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/#mongodb-data-currentOp.startTime">
<code class="leafygreen-ui-1l06pbn">
currentOp.startTime
</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/#mongodb-data-currentOp.samplesPerSecond">
<code class="leafygreen-ui-1l06pbn">
currentOp.samplesPerSecond
</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/#mongodb-data-currentOp.sampledReadsCount">
<code class="leafygreen-ui-1l06pbn">
currentOp.sampledReadsCount
</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/#mongodb-data-currentOp.sampledWritesCount">
<code class="leafygreen-ui-1l06pbn">
currentOp.sampledWritesCount
</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/#mongodb-data-currentOp.sampledReadsBytes">
<code class="leafygreen-ui-1l06pbn">
currentOp.sampledReadsBytes
</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/#mongodb-data-currentOp.sampledWritesBytes">
<code class="leafygreen-ui-1l06pbn">
currentOp.sampledWritesBytes
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$currentOp
</code>
(aggregation) Metrics
<a class="headerlink leafygreen-ui-1kepx47" href="#-currentop--aggregation--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="-currentop--aggregation--metrics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/currentOp/#std-label-current-op-agg">
currentOp
</a>
aggregation stage includes these new fields:
</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/currentOp/#mongodb-data--currentOp.collUuid">
<code class="leafygreen-ui-1l06pbn">
$currentOp.collUuid
</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/currentOp/#mongodb-data--currentOp.startTime">
<code class="leafygreen-ui-1l06pbn">
$currentOp.startTime
</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/currentOp/#mongodb-data--currentOp.samplesPerSecond">
<code class="leafygreen-ui-1l06pbn">
$currentOp.samplesPerSecond
</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/currentOp/#mongodb-data--currentOp.sampledReadsCount">
<code class="leafygreen-ui-1l06pbn">
$currentOp.sampledReadsCount
</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/currentOp/#mongodb-data--currentOp.sampledWritesCount">
<code class="leafygreen-ui-1l06pbn">
$currentOp.sampledWritesCount
</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/currentOp/#mongodb-data--currentOp.sampledReadsBytes">
<code class="leafygreen-ui-1l06pbn">
$currentOp.sampledReadsBytes
</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/currentOp/#mongodb-data--currentOp.sampledWritesBytes">
<code class="leafygreen-ui-1l06pbn">
$currentOp.sampledWritesBytes
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compound Wildcard Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-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="compound-wildcard-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/index-wildcard-compound/#std-label-wildcard-index-compound">
compound wildcard indexes
</a>
. A compound wildcard index has one wildcard
term and one or more additional index terms.
</p>
<p class="leafygreen-ui-1kp3ins">
Use compound wildcard indexes to support queries on known patterns and
to limit the total number of indexes in a collection.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Large Change Stream Events
<a class="headerlink leafygreen-ui-1kepx47" href="#large-change-stream-events" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="large-change-stream-events">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, if you have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change stream
</a>
events larger than 16 MB, you can use the new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#mongodb-pipeline-pipe.-changeStreamSplitLargeEvent">
<code class="leafygreen-ui-1l06pbn">
$changeStreamSplitLargeEvent
</code>
</a>
stage to split the events into
smaller fragments.
</p>
<p class="leafygreen-ui-1kp3ins">
The following new metrics report information about large change stream
events:
</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/serverStatus/#mongodb-serverstatus-serverstatus.metrics.changeStreams">
<code class="leafygreen-ui-1l06pbn">
metrics.changeStreams
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.metrics.changeStreams.largeEventsFailed">
<code class="leafygreen-ui-1l06pbn">
metrics.changeStreams.largeEventsFailed
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.metrics.changeStreams.largeEventsSplit">
<code class="leafygreen-ui-1l06pbn">
metrics.changeStreams.largeEventsSplit
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
serverStatus Output Change
<a class="headerlink leafygreen-ui-1kepx47" href="#serverstatus-output-change" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="serverstatus-output-change">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-dbcommand-dbcmd.serverStatus">
<code class="leafygreen-ui-1l06pbn">
serverStatus
</code>
</a>
includes the following new fields in its
output:
</p>
<dl>
<dt>
Plan Cache Metrics
</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/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.planCache">
<code class="leafygreen-ui-1l06pbn">
planCache
</code>
</a>
</p>
</li>
</ul>
</dd>
<dt>
queryAnalyzer Metrics
</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/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.activeCollections">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.activeCollections
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.totalCollections">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.totalCollections
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.totalSampledReadsCount">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.totalSampledReadsCount
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.totalSampledWritesCount">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.totalSampledWritesCount
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.totalSampledReadsBytes">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.totalSampledReadsBytes
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.queryAnalyzers.totalSampledWritesBytes">
<code class="leafygreen-ui-1l06pbn">
queryAnalyzers.totalSampledWritesBytes
</code>
</a>
</p>
</li>
</ul>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Slot-Based Query Execution Engine
<a class="headerlink leafygreen-ui-1kepx47" href="#slot-based-query-execution-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="slot-based-query-execution-engine">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/sbe/#std-label-sbe-landing">
slot-based query execution engine
</a>
improves
performance for a wider range of find and aggregation queries.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-json-examples-slow-op">
Slow query log messages
</a>
now
include a
<code class="leafygreen-ui-1l06pbn">
queryFramework
</code>
field that indicates which query engine
completed the query:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
queryFramework: "classic"
</code>
indicates that the classic engine
completed the query.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
queryFramework: "sbe"
</code>
indicates that the slot-based query execution engine completed the
query.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
User Roles System Variable
<a class="headerlink leafygreen-ui-1kepx47" href="#user-roles-system-variable" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-roles-system-variable">
</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 the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-roles">
roles
</a>
of the current user.
</p>
<p class="leafygreen-ui-1kp3ins">
For use cases that include
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.find/#std-label-find-user-roles-system-variable-example">
find
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setIntersection/#std-label-setIntersection-user-roles-system-variable-example">
aggregation
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/create-view/#std-label-create-view-user-roles-system-variable-example">
view
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-example-user-roles-system-variable">
updateOne
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateMany/#std-label-updateMany-example-user-roles-system-variable">
updateMany
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-findAndModify-example-user-roles-system-variable">
findAndModify
</a>
examples.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
New Sharding Statistics for Chunk Migrations
<a class="headerlink leafygreen-ui-1kepx47" href="#new-sharding-statistics-for-chunk-migrations" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="new-sharding-statistics-for-chunk-migrations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Available starting in MongoDB 7.1 (and 7.0, 6.3.2, 6.0.6, and 5.0.18).
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB includes the following new sharding statistics for chunk
migrations:
</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/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDonorMoveChunkCommitted">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countDonorMoveChunkCommitted
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDonorMoveChunkAborted">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countDonorMoveChunkAborted
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.totalDonorMoveChunkTimeMillis">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.totalDonorMoveChunkTimeMillis
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countBytesClonedOnRecipient">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countBytesClonedOnRecipient
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDocsClonedOnCatchUpOnRecipient">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countDocsClonedOnCatchUpOnRecipient
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countBytesClonedOnCatchUpOnRecipient">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countBytesClonedOnCatchUpOnRecipient
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
New Slow Query Log Message
<a class="headerlink leafygreen-ui-1kepx47" href="#new-slow-query-log-message" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="new-slow-query-log-message">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0 (and 6.0.13, 5.0.24), the
<code class="leafygreen-ui-1l06pbn">
totalOplogSlotDurationMicros
</code>
in the slow query log message shows the
time between a write operation getting a commit timestamp to commit the
storage engine writes and actually committing.
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
supports
parallel writes. However, it commits write operations with commit
timestamps in any order.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-slow-ops">
Logging Slow Operations
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
New Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#new-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="new-parameters">
</div>
</a>
</h3>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
analyzeShardKey-related Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#analyzeshardkey-related-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="analyzeshardkey-related-parameters">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the following parameters related to the
<code class="leafygreen-ui-1l06pbn">
analyzeShardKey
</code>
command:
</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/parameters/#mongodb-parameter-param.analyzeShardKeyCharacteristicsDefaultSampleSize">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKeyCharacteristicsDefaultSampleSize
</code>
</a>
</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.analyzeShardKeyNumMostCommonValues">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKeyNumMostCommonValues
</code>
</a>
</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.analyzeShardKeyNumRanges">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKeyNumRanges
</code>
</a>
</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.analyzeShardKeyMonotonicityCorrelationCoefficientThreshold">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKeyMonotonicityCorrelationCoefficientThreshold
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
autoMergerIntervalSecs Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#automergerintervalsecs-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="automergerintervalsecs-parameter">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerIntervalSecs">
<code class="leafygreen-ui-1l06pbn">
autoMergerIntervalSecs
</code>
</a>
parameter
which, when AutoMerger is enabled, specifies the amount of
time between automerging rounds, in seconds.
<code class="leafygreen-ui-1l06pbn">
autoMergerIntervalSecs
</code>
can only be set on config servers of sharded
clusters.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
autoMergerThrottlingMS Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#automergerthrottlingms-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="automergerthrottlingms-parameter">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.autoMergerThrottlingMS">
<code class="leafygreen-ui-1l06pbn">
autoMergerThrottlingMS
</code>
</a>
which, when
AutoMerger is enabled, specifies the minimum amount time
between merges initiated by the AutoMerger on the same
collection, in milliseconds.
<code class="leafygreen-ui-1l06pbn">
autoMergerThrottlingMS
</code>
can only be set
on config servers of sharded clusters.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
balancerMigrationsThrottlingMs Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#balancermigrationsthrottlingms-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="balancermigrationsthrottlingms-parameter">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.balancerMigrationsThrottlingMs">
<code class="leafygreen-ui-1l06pbn">
balancerMigrationsThrottlingMs
</code>
</a>
parameter which allows you to throttle the balancing rate.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
enableDetailedConnectionHealthMetricLogLines Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#enabledetailedconnectionhealthmetricloglines-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="enabledetailedconnectionhealthmetricloglines-parameter">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.enableDetailedConnectionHealthMetricLogLines">
<code class="leafygreen-ui-1l06pbn">
enableDetailedConnectionHealthMetricLogLines
</code>
</a>
parameter which lets you specify whether or not a set of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-messages-ref">
log messages
</a>
related to cluster connection health metrics appears in the
log.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
oidcIdentityProviders
</code>
Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#oidcidentityproviders-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="oidcidentityproviders-parameter">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.oidcIdentityProviders">
<code class="leafygreen-ui-1l06pbn">
oidcIdentityProviders
</code>
</a>
parameter which allows
you to specify identity provider (IDP) configurations when using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-oidc/#std-label-authentication-oidc">
OpenID Connect
</a>
authentication.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
configureQueryAnalysis-related Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#configurequeryanalysis-related-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="configurequeryanalysis-related-parameters">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the following parameters related to the
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalysis
</code>
command:
</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/parameters/#mongodb-parameter-param.queryAnalysisSamplerConfigurationRefreshSecs">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisSamplerConfigurationRefreshSecs
</code>
</a>
</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.queryAnalysisWriterIntervalSecs">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisWriterIntervalSecs
</code>
</a>
</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.queryAnalysisWriterMaxMemoryUsageBytes">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisWriterMaxMemoryUsageBytes
</code>
</a>
</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.queryAnalysisWriterMaxBatchSize">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisWriterMaxBatchSize
</code>
</a>
</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.queryAnalysisSampleExpirationSecs">
<code class="leafygreen-ui-1l06pbn">
queryAnalysisSampleExpirationSecs
</code>
</a>
</p>
</li>
</ul>
</section>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Security
<a class="headerlink leafygreen-ui-1kepx47" href="#security" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="security">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Queryable Encryption General Availability
<a class="headerlink leafygreen-ui-1kepx47" href="#queryable-encryption-general-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="queryable-encryption-general-availability">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption with equality
queries
</a>
is generally available (GA).
Improvements in the GA make it incompatible with the
Queryable Encryption Public Preview, which should not be used now that the feature is GA.
For details, see
<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>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
KMIP 1.0 and 1.1 Support
<a class="headerlink leafygreen-ui-1kepx47" href="#kmip-1.0-and-1.1-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="kmip-1.0-and-1.1-support">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 (and 6.0.6) adds 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. This setting allows MongoDB
servers to connect to KMIP servers that use KMIP protocol version 1.0 or
1.1.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
OpenSSL and FIPS Support
<a class="headerlink leafygreen-ui-1kepx47" href="#openssl-and-fips-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="openssl-and-fips-support">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0 and 6.0.7, MongoDB supports OpenSSL 3.0 and the
OpenSSL FIPS provider with these operating systems:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Red Hat Enterprise Linux 9
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Amazon Linux 2023
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Ubuntu Linux 22.04
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, MongoDB supports OpenSSL 3.0 and the OpenSSL
FIPS provider for Amazon Linux 2023.3.
</p>
<p class="leafygreen-ui-1kp3ins">
For details, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-transport-encryption/#std-label-transport-encryption">
TLS/SSL (Transport Encryption)
<!-- -->
.
</a>
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
OpenID Connect
<a class="headerlink leafygreen-ui-1kepx47" href="#openid-connect" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="openid-connect">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Starting in 7.0, MongoDB Enterprise provides support for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-oidc/#std-label-authentication-oidc">
OpenID Connect
</a>
authentication. OpenID Connect is an
authentication layer built on top of OAuth2. You can use OpenID Connect to
configure single sign-on between your MongoDB database and a third-party identity
provider.
</p>
</section>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Aggregation
<a class="headerlink leafygreen-ui-1kepx47" href="#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="aggregation">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
New operators:
</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>
Name
</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/aggregation/median/#mongodb-group-grp.-median">
<code class="leafygreen-ui-1l06pbn">
$median
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Returns an approximation of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-median">
median
</a>
, the 50th
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-percentile">
percentile
</a>
, as a scalar value.
</p>
<p class="leafygreen-ui-1kp3ins">
This operator can be used as an accumulator and as an aggregation
expression.
</p>
</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/aggregation/percentile/#mongodb-group-grp.-percentile">
<code class="leafygreen-ui-1l06pbn">
$percentile
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Returns an array of scalar values that correspond to specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-percentile">
percentile
</a>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
This operator can be used as an accumulator and as an aggregation
expression.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Month Name Specifier for $dateToString
<a class="headerlink leafygreen-ui-1kepx47" href="#month-name-specifier-for--datetostring" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="month-name-specifier-for--datetostring">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the following format specifiers to use with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString">
<code class="leafygreen-ui-1l06pbn">
$dateToString
</code>
</a>
operator:
</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="">
<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 name (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">
dec
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<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>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-time-series">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Time Series
<a class="headerlink leafygreen-ui-1kepx47" href="#time-series" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 removes most of the time series limitations from these
operations that are based on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/delete/#mongodb-dbcommand-dbcmd.delete">
<code class="leafygreen-ui-1l06pbn">
delete
</code>
</a>
command:
</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/delete/#mongodb-dbcommand-dbcmd.delete">
<code class="leafygreen-ui-1l06pbn">
delete
</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.deleteOne/#mongodb-method-db.collection.deleteOne">
<code class="leafygreen-ui-1l06pbn">
deleteOne()
</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.deleteMany/#mongodb-method-db.collection.deleteMany">
<code class="leafygreen-ui-1l06pbn">
deleteMany()
</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.delete/#mongodb-method-Bulk.find.delete">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.delete()
</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.deleteOne/#mongodb-method-Bulk.find.deleteOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.deleteOne()
</code>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-sharding">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Sharding
<a class="headerlink leafygreen-ui-1kepx47" href="#sharding" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sharding">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sharding Metadata Diagnostics
<a class="headerlink leafygreen-ui-1kepx47" href="#sharding-metadata-diagnostics" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sharding-metadata-diagnostics">
</div>
</a>
</h3>
<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 at the cluster, database, and
collection levels for inconsistencies. These inconsistencies can originate
in cases such as:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Upgrades in cases where the cluster encountered a bug while running previous
releases of MongoDB
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Manual interventions that corrupt the cluster catalog
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The following helper methods are now available through
<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>
</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.checkMetadataConsistency/#mongodb-method-db.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
db.checkMetadataConsistency()
</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.checkMetadataConsistency/#mongodb-method-db.collection.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
db.collection.checkMetadataConsistency()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.checkMetadataConsistency/#mongodb-method-sh.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
sh.checkMetadataConsistency()
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information on the inconsistencies the command checks for, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/inconsistency-type/#std-label-inconsistency-types">
Inconsistency Types
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
mergeAllChunksOnShard Command
<a class="headerlink leafygreen-ui-1kepx47" href="#mergeallchunksonshard-command" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mergeallchunksonshard-command">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#mongodb-dbcommand-dbcmd.mergeAllChunksOnShard">
<code class="leafygreen-ui-1l06pbn">
mergeAllChunksOnShard
</code>
</a>
command
finds and merges all
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mergeAllChunksOnShard/#std-label-mergeability">
mergeable chunks
</a>
that a shard
owns for a given collection.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
The AutoMerger
<a class="headerlink leafygreen-ui-1kepx47" href="#the-automerger" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="the-automerger">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept">
the AutoMerger
</a>
can automatically merge chunks that meet the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-mergeability-concept">
mergeability requirements
</a>
. The
AutoMerger is enabled by default.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can use the following methods to control
the AutoMerger behavior:
</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/sh.startAutoMerger/#mongodb-method-sh.startAutoMerger">
<code class="leafygreen-ui-1l06pbn">
sh.startAutoMerger()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.stopAutoMerger/#mongodb-method-sh.stopAutoMerger">
<code class="leafygreen-ui-1l06pbn">
sh.stopAutoMerger()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.enableAutoMerger/#mongodb-method-sh.enableAutoMerger">
<code class="leafygreen-ui-1l06pbn">
sh.enableAutoMerger()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.disableAutoMerger/#mongodb-method-sh.disableAutoMerger">
<code class="leafygreen-ui-1l06pbn">
sh.disableAutoMerger()
</code>
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
enableAutoMerger Parameter for configureCollectionBalancing
<a class="headerlink leafygreen-ui-1kepx47" href="#enableautomerger-parameter-for-configurecollectionbalancing" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enableautomerger-parameter-for-configurecollectionbalancing">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing">
<code class="leafygreen-ui-1l06pbn">
configureCollectionBalancing
</code>
</a>
command accepts the
<code class="leafygreen-ui-1l06pbn">
enableAutoMerger
</code>
parameter. Use
<code class="leafygreen-ui-1l06pbn">
enableAutoMerger
</code>
to set whether or not the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept">
AutoMerger
</a>
takes this collection
into account.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
rangeDeleterHighPriority Parameter for Deprioritizing Range deletions
<a class="headerlink leafygreen-ui-1kepx47" href="#rangedeleterhighpriority-parameter-for-deprioritizing-range-deletions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rangedeleterhighpriority-parameter-for-deprioritizing-range-deletions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you can prioritize or deprioritize cleanup of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
</a>
over user operations
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterHighPriority">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterHighPriority
</code>
</a>
parameter.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
operationsBlockedByRefresh Metrics Removed
<a class="headerlink leafygreen-ui-1kepx47" href="#operationsblockedbyrefresh-metrics-removed" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="operationsblockedbyrefresh-metrics-removed">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 removes the
<code class="leafygreen-ui-1l06pbn">
operationsBlockedByRefresh
</code>
document that
contains statistics about operations blocked by catalog cache refresh
activity because the
<code class="leafygreen-ui-1l06pbn">
operationsBlockedByRefresh
</code>
counters increased
on
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
for every operation that used collection routing
information even if the operation wasn't blocked by a catalog refresh
activity.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
analyzeShardKey Command and db.collection.analyzeShardKey() Method
<a class="headerlink leafygreen-ui-1kepx47" href="#analyzeshardkey-command-and-db.collection.analyzeshardkey---method" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="analyzeshardkey-command-and-db.collection.analyzeshardkey---method">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/analyzeShardKey/#mongodb-dbcommand-dbcmd.analyzeShardKey">
<code class="leafygreen-ui-1l06pbn">
analyzeShardKey
</code>
</a>
command and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.analyzeShardKey/#mongodb-method-db.collection.analyzeShardKey">
<code class="leafygreen-ui-1l06pbn">
db.collection.analyzeShardKey()
</code>
</a>
method, which let you
calculate metrics for evaluating a shard key.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
configureQueryAnalyzer Command and db.collection.configureQueryAnalyzer() Method
<a class="headerlink leafygreen-ui-1kepx47" href="#configurequeryanalyzer-command-and-db.collection.configurequeryanalyzer---method" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-command-and-db.collection.configurequeryanalyzer---method">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 adds the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureQueryAnalyzer/#mongodb-dbcommand-dbcmd.configureQueryAnalyzer">
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
</a>
command, which
allows you to configure query sampling for a collection. MongoDB 7.0
also adds the
<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>
, which
wraps the
<code class="leafygreen-ui-1l06pbn">
configureQueryAnalyzer
</code>
command. Sampled queries provide
information to
<code class="leafygreen-ui-1l06pbn">
analyzeShardKey
</code>
to calculate metrics about read and
write distribution of a shard key.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-rapid-release-changes">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Changes Introduced in 6.X-Series Rapid Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#changes-introduced-in-6.x-series-rapid-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="changes-introduced-in-6.x-series-rapid-releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 includes changes and features from the following Rapid
Release versions:
</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/v6.1/release-notes/" target="_self">
<span>
MongoDB 6.1 Release Notes
</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/v6.2/release-notes/" target="_self">
<span>
MongoDB 6.2 Release Notes
</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/v6.3/release-notes/" target="_self">
<span>
MongoDB 6.3 Release Notes
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-rel-notes-platforms">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Platform Support
<a class="headerlink leafygreen-ui-1kepx47" href="#platform-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="platform-support">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Removed Platforms
<a class="headerlink leafygreen-ui-1kepx47" href="#removed-platforms" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="removed-platforms">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 removes support for
<strong>
RHEL 7 / CentOS 7 / Oracle 7
</strong>
on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-PPC64LE">
PPC64LE
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-s390x">
s390x
</a>
architectures.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-upgrade">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Upgrade Procedures
<a class="headerlink leafygreen-ui-1kepx47" href="#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="upgrade-procedures">
</div>
</a>
</h2>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Feature Compatibility Version
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
To upgrade to MongoDB 7.0 from a 6.0 deployment, the 6.0 deployment
must have
<code class="leafygreen-ui-1l06pbn">
featureCompatibilityVersion
</code>
set to
<code class="leafygreen-ui-1l06pbn">
6.0
</code>
. To check
the version:
</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>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To upgrade to MongoDB 7.0, refer to the upgrade instructions specific to
your MongoDB deployment:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-upgrade-standalone/#std-label-7.0-upgrade-standalone">
Upgrade a Standalone to 7.0
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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">
<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>
<p class="leafygreen-ui-1kp3ins">
If you need guidance on upgrading to 7.0, MongoDB professional services
offer major version upgrade support to help ensure a smooth transition
without interruption to your MongoDB application. To learn more, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/consulting?tck=docs_server" target="_self">
<span>
MongoDB Consulting
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-downgrade-considerations">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Downgrade Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-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="downgrade-considerations">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Only Single-Version Downgrades are Supported
<a class="headerlink leafygreen-ui-1kepx47" href="#only-single-version-downgrades-are-supported" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="only-single-version-downgrades-are-supported">
</div>
</a>
</h3>
<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
<!-- -->
7.0-series
<!-- -->
to a
<!-- -->
6.0-series
<!-- -->
deployment.
However, further downgrading that
<!-- -->
6.0-series
<!-- -->
deployment to a
<!-- -->
5.0-series
<!-- -->
deployment is not supported.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Downgrade Policy Changes
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-policy-changes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-policy-changes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Binary downgrades are no longer supported for MongoDB Community Edition.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot downgrade your deployment's
<span class="leafygreen-ui-vm4wms" tabindex="0">
fCV
</span>
to or from a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-rapid-releases">
rapid release
</a>
version of MongoDB.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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 requires an
additional parameter,
<code class="leafygreen-ui-1l06pbn">
confirm
</code>
, which must be set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to
upgrade or downgrade
<span class="leafygreen-ui-vm4wms" tabindex="0">
fCV
</span>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you upgrade or downgrade your deployment's
<span class="leafygreen-ui-vm4wms" tabindex="0">
fCV
</span>
, you cannot
downgrade your Enterprise deployment's binary version without assistance from
support.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Backward-Incompatible Features
<a class="headerlink leafygreen-ui-1kepx47" href="#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="backward-incompatible-features">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 7.0 includes features that are not compatible with earlier releases.
Downgrading from 7.0 to an earlier release requires that you remove data
that uses these features.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/7.0-compatibility/#std-label-7.0-downgrade-incompatible">
Backward-Incompatible Features
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-7.0-download">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Download
<a class="headerlink leafygreen-ui-1kepx47" href="#download" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To download MongoDB 7.0, go to 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>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Report an Issue
<a class="headerlink leafygreen-ui-1kepx47" href="#report-an-issue" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-an-issue">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To report an issue, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://github.com/mongodb/mongo/wiki/Submit-Bug-Reports" rel="noopener noreferrer">
<span>
MongoDB 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>
for
instructions on how to file a JIRA ticket for the MongoDB server or one
of the related projects.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.collection.dropSearchIndex/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.collection.dropSearchIndex()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.dropsearchindex--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.collection.dropsearchindex--">
</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="#access-control" target="_self">
<span>
Access Control
</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.collection.dropSearchIndex()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.dropSearchIndex" 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.collection.dropSearchIndex">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.0
</em>
:
<!-- -->
<!-- -->
(
<em>
Also available starting in 6.0.7
</em>
)
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Deletes an existing
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self">
<span>
Atlas Search index
</span>
</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/dropSearchIndex/#mongodb-dbcommand-dbcmd.dropSearchIndex">
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex
</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>
</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 M0, M2, and M5 clusters or 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>
</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">
Command syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.<collection>.dropSearchIndex(<name>)","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.<!-- --><<!-- -->collection<!-- -->><!-- -->.<span class="lg-highlight-title lg-highlight-function">dropSearchIndex</span>(<<!-- -->name<!-- -->><!-- -->)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex()
</code>
takes 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: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>
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">
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>
Required
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Name of the search index to drop.
</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">
After you run
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex()
</code>
, there may be a delay between when you
receive a response from the command and when the index is deleted.
</p>
<p class="leafygreen-ui-1kp3ins">
To see the status of your search indexes, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/listSearchIndexes/#mongodb-pipeline-pipe.-listSearchIndexes">
<code class="leafygreen-ui-1l06pbn">
$listSearchIndexes
</code>
</a>
aggregation stage. Once your index is
deleted, that index no longer appears in the
<code class="leafygreen-ui-1l06pbn">
$listSearchIndexes
</code>
output.
</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 enforces access control, the user running the
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex()
</code>
method must have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-dropSearchIndex">
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex
</code>
</a>
privilege action on the database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ resource: { database : true }, actions: [ \"dropSearchIndex\" ] }","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">resource</span>: <!-- -->{ <!-- -->database <!-- -->: <span class="lg-highlight-literal">true</span> }<!-- -->, <span class="lg-highlight-attr">actions</span>: <!-- -->[ <span class="lg-highlight-string">"dropSearchIndex"</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 built-in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-dbAdmin">
<code class="leafygreen-ui-1l06pbn">
dbAdmin
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-readWrite">
<code class="leafygreen-ui-1l06pbn">
readWrite
</code>
</a>
roles provide
the
<code class="leafygreen-ui-1l06pbn">
dropSearchIndex
</code>
privilege. The following example grants the
<code class="leafygreen-ui-1l06pbn">
readWrite
</code>
role on the
<code class="leafygreen-ui-1l06pbn">
qa
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.grantRolesToUser(\n \"<user>\",\n [ { role: \"readWrite\", db: \"qa\" } ]\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">grantRolesToUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<user>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"readWrite"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"qa"</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">
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 deletes a search index named
<code class="leafygreen-ui-1l06pbn">
searchIndex01
</code>
on
the
<code class="leafygreen-ui-1l06pbn">
movies
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.movies.dropSearchIndex(\"searchIndex01\")","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">movies</span>.<span class="lg-highlight-title lg-highlight-function">dropSearchIndex</span>(<span class="lg-highlight-string">"searchIndex01"</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/replaceWith/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$replaceWith (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-replacewith--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="-replacewith--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="pipeline">
<dt>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-replaceWith" 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.-replaceWith">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Replaces the input document with the specified document. The
operation replaces all existing fields in the input document,
including the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field. With
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
, you can
promote an embedded document to the top-level. You can also specify
a new document as the replacement.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
stage performs the same action as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot">
<code class="leafygreen-ui-1l06pbn">
$replaceRoot
</code>
</a>
stage, but the stages have different forms.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
stage has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $replaceWith: <replacementdocument> }","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">$replaceWith</span>: <<!-- -->replacementDocument<!-- -->> <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 replacement document 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 document.
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
<code class="leafygreen-ui-1l06pbn">
<replacementDocument>
</code>
is not a document,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
errors and fails.
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
<replacementDocument>
</code>
resolves to a missing document (i.e.
the document does not exist),
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
errors and
fails. For example, create a 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.collection.insertMany([\n { \"_id\": 1, \"name\" : { \"first\" : \"John\", \"last\" : \"Backus\" } },\n { \"_id\": 2, \"name\" : { \"first\" : \"John\", \"last\" : \"McCarthy\" } },\n { \"_id\": 3, \"name\": { \"first\" : \"Grace\", \"last\" : \"Hopper\" } },\n { \"_id\": 4, \"firstname\": \"Ole-Johan\", \"lastname\" : \"Dahl\" },\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">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">"name"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"John"</span>, <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"Backus"</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">"name"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"John"</span>, <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"McCarthy"</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">"name"</span>: <!-- -->{ <span class="lg-highlight-string">"first"</span> <!-- -->: <span class="lg-highlight-string">"Grace"</span>, <span class="lg-highlight-string">"last"</span> <!-- -->: <span class="lg-highlight-string">"Hopper"</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">"firstname"</span>: <span class="lg-highlight-string">"Ole-Johan"</span>, <span class="lg-highlight-string">"lastname"</span> <!-- -->: <span class="lg-highlight-string">"Dahl"</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 the following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
operation fails because one
of the document does not have the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate([\n { $replaceWith: \"$name\" }\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">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <span class="lg-highlight-string">"$name"</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 the error, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/mergeObjects/#mongodb-expression-exp.-mergeObjects">
<code class="leafygreen-ui-1l06pbn">
$mergeObjects
</code>
</a>
to merge
the
<code class="leafygreen-ui-1l06pbn">
name
</code>
document with some default document; for example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate([\n { $replaceWith: { $mergeObjects: [ { _id: \"$_id\", first: \"\", last: \"\" }, \"$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-property">collection</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">$replaceWith</span>: <!-- -->{ <span class="lg-highlight-attr">$mergeObjects</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$_id"</span>, <span class="lg-highlight-attr">first</span>: <span class="lg-highlight-string">""</span>, <span class="lg-highlight-attr">last</span>: <span class="lg-highlight-string">""</span> }<!-- -->, <span class="lg-highlight-string">"$name"</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">
Alternatively, you can skip the documents that are missing the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field by
including a
<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 to check for existence of the
document field before passing documents to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
stage:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate([\n { $match: { name : { $exists: true, $not: { $type: \"array\" }, $type: \"object\" } } },\n { $replaceWith: \"$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-property">collection</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>: <!-- -->{ <!-- -->name <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$exists</span>: <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-attr">$not</span>: <!-- -->{ <span class="lg-highlight-attr">$type</span>: <span class="lg-highlight-string">"array"</span> }<!-- -->, <span class="lg-highlight-attr">$type</span>: <span class="lg-highlight-string">"object"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <span class="lg-highlight-string">"$name"</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">
Or, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/ifNull/#mongodb-expression-exp.-ifNull">
<code class="leafygreen-ui-1l06pbn">
$ifNull
</code>
</a>
expression to specify some other
document to be root; for example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.aggregate([\n { $replaceWith: { $ifNull: [ \"$name\", { _id: \"$_id\", missingName: 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">collection</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">$replaceWith</span>: <!-- -->{ <span class="lg-highlight-attr">$ifNull</span>: <!-- -->[ <span class="lg-highlight-string">"$name"</span>, <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$_id"</span>, <span class="lg-highlight-attr">missingName</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>
<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-replacewith-match">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
an Embedded Document Field
<a class="headerlink leafygreen-ui-1kepx47" href="#-replacewith-an-embedded-document-field" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-replacewith-an-embedded-document-field">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a collection named
<code class="leafygreen-ui-1l06pbn">
people
</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.people.insertMany([\n { \"_id\" : 1, \"name\" : \"Arlene\", \"age\" : 34, \"pets\" : { \"dogs\" : 2, \"cats\" : 1 } },\n { \"_id\" : 2, \"name\" : \"Sam\", \"age\" : 41, \"pets\" : { \"cats\" : 1, \"fish\" : 3 } },\n { \"_id\" : 3, \"name\" : \"Maria\", \"age\" : 25 }\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">people</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">"name"</span> <!-- -->: <span class="lg-highlight-string">"Arlene"</span>, <span class="lg-highlight-string">"age"</span> <!-- -->: <span class="lg-highlight-number">34</span>, <span class="lg-highlight-string">"pets"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"dogs"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"cats"</span> <!-- -->: <span class="lg-highlight-number">1</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">"name"</span> <!-- -->: <span class="lg-highlight-string">"Sam"</span>, <span class="lg-highlight-string">"age"</span> <!-- -->: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-string">"pets"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"cats"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"fish"</span> <!-- -->: <span class="lg-highlight-number">3</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">"name"</span> <!-- -->: <span class="lg-highlight-string">"Maria"</span>, <span class="lg-highlight-string">"age"</span> <!-- -->: <span class="lg-highlight-number">25</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-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
stage to
replace each input document with the result of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/mergeObjects/#mongodb-expression-exp.-mergeObjects">
<code class="leafygreen-ui-1l06pbn">
$mergeObjects
</code>
</a>
operation. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/mergeObjects/#mongodb-expression-exp.-mergeObjects">
<code class="leafygreen-ui-1l06pbn">
$mergeObjects
</code>
</a>
expression merges the specified default document with the
<code class="leafygreen-ui-1l06pbn">
pets
</code>
document.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.aggregate( [\n { $replaceWith: { $mergeObjects: [ { dogs: 0, cats: 0, birds: 0, fish: 0 }, \"$pets\" ] } }\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">people</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">$replaceWith</span>: <!-- -->{ <span class="lg-highlight-attr">$mergeObjects</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">dogs</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">cats</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">birds</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">fish</span>: <span class="lg-highlight-number">0</span> }<!-- -->, <span class="lg-highlight-string">"$pets"</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":"{ \"dogs\" : 2, \"cats\" : 1, \"birds\" : 0, \"fish\" : 0 }\n{ \"dogs\" : 0, \"cats\" : 1, \"birds\" : 0, \"fish\" : 3 }\n{ \"dogs\" : 0, \"cats\" : 0, \"birds\" : 0, \"fish\" : 0 }","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">"dogs"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"cats"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"birds"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"fish"</span> <!-- -->: <span class="lg-highlight-number">0</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"dogs"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"cats"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"birds"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"fish"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"dogs"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"cats"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"birds"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"fish"</span> <!-- -->: <span class="lg-highlight-number">0</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
a Document Nested in an Array
<a class="headerlink leafygreen-ui-1kepx47" href="#-replacewith-a-document-nested-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="-replacewith-a-document-nested-in-an-array">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
A collection named
<code class="leafygreen-ui-1l06pbn">
students
</code>
contains the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.insertMany([\n {\n \"_id\" : 1,\n \"grades\" : [\n { \"test\": 1, \"grade\" : 80, \"mean\" : 75, \"std\" : 6 },\n { \"test\": 2, \"grade\" : 85, \"mean\" : 90, \"std\" : 4 },\n { \"test\": 3, \"grade\" : 95, \"mean\" : 85, \"std\" : 6 }\n ]\n },\n {\n \"_id\" : 2,\n \"grades\" : [\n { \"test\": 1, \"grade\" : 90, \"mean\" : 75, \"std\" : 6 },\n { \"test\": 2, \"grade\" : 87, \"mean\" : 90, \"std\" : 3 },\n { \"test\": 3, \"grade\" : 91, \"mean\" : 85, \"std\" : 4 }\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">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">"test"</span>: <span class="lg-highlight-number">1</span>, <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">"test"</span>: <span class="lg-highlight-number">2</span>, <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">"test"</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">95</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">"test"</span>: <span class="lg-highlight-number">1</span>, <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">"test"</span>: <span class="lg-highlight-number">2</span>, <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">"test"</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">91</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><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 promotes the embedded document(s) with the
<code class="leafygreen-ui-1l06pbn">
grade
</code>
field greater than or equal to
<code class="leafygreen-ui-1l06pbn">
90
</code>
to the top level:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.aggregate( [\n { $unwind: \"$grades\" },\n { $match: { \"grades.grade\" : { $gte: 90 } } },\n { $replaceWith: \"$grades\" }\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">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unwind</span>: <span class="lg-highlight-string">"$grades"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-string">"grades.grade"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">90</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <span class="lg-highlight-string">"$grades"</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":"{ \"test\" : 3, \"grade\" : 95, \"mean\" : 85, \"std\" : 6 }\n{ \"test\" : 1, \"grade\" : 90, \"mean\" : 75, \"std\" : 6 }\n{ \"test\" : 3, \"grade\" : 91, \"mean\" : 85, \"std\" : 4 }","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">"test"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">95</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">{ <span class="lg-highlight-string">"test"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <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">"test"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"grade"</span> <!-- -->: <span class="lg-highlight-number">91</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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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-replacewith-new-doc">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
a Newly Created Document
<a class="headerlink leafygreen-ui-1kepx47" href="#-replacewith-a-newly-created-document" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-replacewith-a-newly-created-document">
</div>
</a>
</h3>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Example 1
<a class="headerlink leafygreen-ui-1kepx47" href="#example-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="example-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
An example collection
<code class="leafygreen-ui-1l06pbn">
sales
</code>
is populated 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\" : \"butter\", \"price\" : 10, \"quantity\": 2, date: ISODate(\"2019-03-01T08:00:00Z\"), status: \"C\" },\n { \"_id\" : 2, \"item\" : \"cream\", \"price\" : 20, \"quantity\": 1, date: ISODate(\"2019-03-01T09:00:00Z\"), status: \"A\" },\n { \"_id\" : 3, \"item\" : \"jam\", \"price\" : 5, \"quantity\": 10, date: ISODate(\"2019-03-15T09:00:00Z\"), status: \"C\" },\n { \"_id\" : 4, \"item\" : \"muffins\", \"price\" : 5, \"quantity\": 10, date: ISODate(\"2019-03-15T09:00:00Z\"), status: \"C\" }\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">"butter"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-03-01T08:00:00Z"</span>)<!-- -->, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"C"</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">"cream"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-03-01T09:00:00Z"</span>)<!-- -->, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</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">"jam"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-03-15T09:00:00Z"</span>)<!-- -->, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"C"</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">"muffins"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-03-15T09:00:00Z"</span>)<!-- -->, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"C"</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">
Assume that for reporting purposes, you want to calculate for each
completed sale, the total amount as of the current report run time. The
following operation finds all the sales with status
<code class="leafygreen-ui-1l06pbn">
C
</code>
and creates
new documents using the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
stage. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
calculates the total amount as well as uses
the variable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.NOW">
<code class="leafygreen-ui-1l06pbn">
NOW
</code>
</a>
to get the current time.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.aggregate([\n { $match: { status: \"C\" } },\n { $replaceWith: { _id: \"$_id\", item: \"$item\", amount: { $multiply: [ \"$price\", \"$quantity\"]}, status: \"Complete\", asofDate: \"$$NOW\" } }\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">aggregate</span>(<!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"C"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$_id"</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"$item"</span>, <span class="lg-highlight-attr">amount</span>: <!-- -->{ <span class="lg-highlight-attr">$multiply</span>: <!-- -->[ <span class="lg-highlight-string">"$price"</span>, <span class="lg-highlight-string">"$quantity"</span>]}<!-- -->, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Complete"</span>, <span class="lg-highlight-attr">asofDate</span>: <span class="lg-highlight-string">"$$NOW"</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 documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"item\" : \"butter\", \"amount\" : 20, \"status\" : \"Complete\", \"asofDate\" : ISODate(\"2019-06-03T22:47:54.812Z\") }\n{ \"_id\" : 3, \"item\" : \"jam\", \"amount\" : 50, \"status\" : \"Complete\", \"asofDate\" : ISODate(\"2019-06-03T22:47:54.812Z\") }\n{ \"_id\" : 4, \"item\" : \"muffins\", \"amount\" : 50, \"status\" : \"Complete\", \"asofDate\" : ISODate(\"2019-06-03T22:47:54.812Z\") }","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">"butter"</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"Complete"</span>, <span class="lg-highlight-string">"asofDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-03T22:47:54.812Z"</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">"jam"</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"Complete"</span>, <span class="lg-highlight-string">"asofDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-03T22:47:54.812Z"</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">"muffins"</span>, <span class="lg-highlight-string">"amount"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"Complete"</span>, <span class="lg-highlight-string">"asofDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-03T22:47:54.812Z"</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">
Example 2
<a class="headerlink leafygreen-ui-1kepx47" href="#example-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="example-2">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
An example collection
<code class="leafygreen-ui-1l06pbn">
reportedsales
</code>
is populated with the
reported sales information by quarter and regions:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.reportedsales.insertMany( [\n { _id: 1, quarter: \"2019Q1\", region: \"A\", qty: 400 },\n { _id: 2, quarter: \"2019Q1\", region: \"B\", qty: 550 },\n { _id: 3, quarter: \"2019Q1\", region: \"C\", qty: 1000 },\n { _id: 4, quarter: \"2019Q2\", region: \"A\", qty: 660 },\n { _id: 5, quarter: \"2019Q2\", region: \"B\", qty: 500 },\n { _id: 6, quarter: \"2019Q2\", region: \"C\", qty: 1200 }\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">reportedsales</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">quarter</span>: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">400</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">quarter</span>: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">550</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">quarter</span>: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"C"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">1000</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">quarter</span>: <span class="lg-highlight-string">"2019Q2"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">660</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">quarter</span>: <span class="lg-highlight-string">"2019Q2"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">500</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">quarter</span>: <span class="lg-highlight-string">"2019Q2"</span>, <span class="lg-highlight-attr">region</span>: <span class="lg-highlight-string">"C"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">1200</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">
Assume that for reporting purposes, you want to view the reported sales
data by quarter; e.g.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2019Q1\", \"A\" : 400, \"B\" : 550, \"C\" : 1000 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"A"</span> <!-- -->: <span class="lg-highlight-number">400</span>, <span class="lg-highlight-string">"B"</span> <!-- -->: <span class="lg-highlight-number">550</span>, <span class="lg-highlight-string">"C"</span> <!-- -->: <span class="lg-highlight-number">1000</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To view the data grouped by quarter, you can use the following
aggregation pipeline:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.reportedsales.aggregate( [\n { $addFields: { obj: { k: \"$region\", v: \"$qty\" } } },\n { $group: { _id: \"$quarter\", items: { $push: \"$obj\" } } },\n { $project: { items2: { $concatArrays: [ [ { \"k\": \"_id\", \"v\": \"$_id\" } ], \"$items\" ] } } },\n { $replaceWith: { $arrayToObject: \"$items2\" } }\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">reportedsales</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">obj</span>: <!-- -->{ <span class="lg-highlight-attr">k</span>: <span class="lg-highlight-string">"$region"</span>, <span class="lg-highlight-attr">v</span>: <span class="lg-highlight-string">"$qty"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$quarter"</span>, <span class="lg-highlight-attr">items</span>: <!-- -->{ <span class="lg-highlight-attr">$push</span>: <span class="lg-highlight-string">"$obj"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">items2</span>: <!-- -->{ <span class="lg-highlight-attr">$concatArrays</span>: <!-- -->[ <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"k"</span>: <span class="lg-highlight-string">"_id"</span>, <span class="lg-highlight-string">"v"</span>: <span class="lg-highlight-string">"$_id"</span> } ]<!-- -->, <span class="lg-highlight-string">"$items"</span> ] } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <!-- -->{ <span class="lg-highlight-attr">$arrayToObject</span>: <span class="lg-highlight-string">"$items2"</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>
<dl>
<dt>
First stage:
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
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 adds a new
<code class="leafygreen-ui-1l06pbn">
obj
</code>
document
field that defines the key
<code class="leafygreen-ui-1l06pbn">
k
</code>
as the region value and the
value
<code class="leafygreen-ui-1l06pbn">
v
</code>
as the quantity for that region. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"quarter\" : \"2019Q1\", \"region\" : \"A\", \"qty\" : 400, \"obj\" : { \"k\" : \"A\", \"v\" : 400 } }","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-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"quarter"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"region"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">400</span>, <span class="lg-highlight-string">"obj"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">400</span> } }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</dd>
<dt>
Second stage:
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
stage groups by the quarter and uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/push/#mongodb-group-grp.-push">
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</a>
to accumulate the
<code class="leafygreen-ui-1l06pbn">
obj
</code>
fields into a new
<code class="leafygreen-ui-1l06pbn">
items
</code>
array field. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2019Q1\", \"items\" : [ { \"k\" : \"A\", \"v\" : 400 }, { \"k\" : \"B\", \"v\" : 550 }, { \"k\" : \"C\", \"v\" : 1000 } ] }","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-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">400</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">550</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"C"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">1000</span> } ] }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</dd>
<dt>
Third stage:
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
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 uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/concatArrays/#mongodb-expression-exp.-concatArrays">
<code class="leafygreen-ui-1l06pbn">
$concatArrays
</code>
</a>
to
create a new array
<code class="leafygreen-ui-1l06pbn">
items2
</code>
that includes the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
info and the
elements from the
<code class="leafygreen-ui-1l06pbn">
items
</code>
array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2019Q1\", \"items2\" : [ { \"k\" : \"_id\", \"v\" : \"2019Q1\" }, { \"k\" : \"A\", \"v\" : 400 }, { \"k\" : \"B\", \"v\" : 550 }, { \"k\" : \"C\", \"v\" : 1000 } ] }","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-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"items2"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"_id"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"A"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">400</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"B"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">550</span> }<!-- -->, <!-- -->{ <span class="lg-highlight-string">"k"</span> <!-- -->: <span class="lg-highlight-string">"C"</span>, <span class="lg-highlight-string">"v"</span> <!-- -->: <span class="lg-highlight-number">1000</span> } ] }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</dd>
<dt>
Fourth stage:
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/arrayToObject/#mongodb-expression-exp.-arrayToObject">
<code class="leafygreen-ui-1l06pbn">
$arrayToObject
</code>
</a>
to convert the
<code class="leafygreen-ui-1l06pbn">
items2
</code>
into a
document, using the specified key
<code class="leafygreen-ui-1l06pbn">
k
</code>
and value
<code class="leafygreen-ui-1l06pbn">
v
</code>
pairs and
outputs that document to the next stage. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2019Q1\", \"A\" : 400, \"B\" : 550, \"C\" : 1000 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"A"</span> <!-- -->: <span class="lg-highlight-number">400</span>, <span class="lg-highlight-string">"B"</span> <!-- -->: <span class="lg-highlight-number">550</span>, <span class="lg-highlight-string">"C"</span> <!-- -->: <span class="lg-highlight-number">1000</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
The aggregation returns the following document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"2019Q1\", \"A\" : 400, \"B\" : 550, \"C\" : 1000 }\n{ \"_id\" : \"2019Q2\", \"A\" : 660, \"B\" : 500, \"C\" : 1200 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q1"</span>, <span class="lg-highlight-string">"A"</span> <!-- -->: <span class="lg-highlight-number">400</span>, <span class="lg-highlight-string">"B"</span> <!-- -->: <span class="lg-highlight-number">550</span>, <span class="lg-highlight-string">"C"</span> <!-- -->: <span class="lg-highlight-number">1000</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"2019Q2"</span>, <span class="lg-highlight-string">"A"</span> <!-- -->: <span class="lg-highlight-number">660</span>, <span class="lg-highlight-string">"B"</span> <!-- -->: <span class="lg-highlight-number">500</span>, <span class="lg-highlight-string">"C"</span> <!-- -->: <span class="lg-highlight-number">1200</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
a New Document Created from
<code class="leafygreen-ui-1l06pbn">
$$ROOT
</code>
and a Default Document
<a class="headerlink leafygreen-ui-1kepx47" href="#-replacewith-a-new-document-created-from---root-and-a-default-document" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-replacewith-a-new-document-created-from---root-and-a-default-document">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a collection named
<code class="leafygreen-ui-1l06pbn">
contacts
</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.contacts.insertMany( [\n { \"_id\" : 1, name: \"Fred\", email: \"[email protected]\" },\n { \"_id\" : 2, name: \"Frank N. Stine\", cell: \"012-345-9999\" },\n { \"_id\" : 3, name: \"Gren Dell\", cell: \"987-654-3210\", email: \"[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">db.<span class="lg-highlight-property">contacts</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-attr">name</span>: <span class="lg-highlight-string">"Fred"</span>, <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">"[email protected]"</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-attr">name</span>: <span class="lg-highlight-string">"Frank N. Stine"</span>, <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">"012-345-9999"</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-attr">name</span>: <span class="lg-highlight-string">"Gren Dell"</span>, <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">"987-654-3210"</span>, <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">"[email protected]"</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
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-replaceWith" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</span>
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/mergeObjects/#mongodb-expression-exp.-mergeObjects">
<code class="leafygreen-ui-1l06pbn">
$mergeObjects
</code>
</a>
to output current documents with default
values for missing fields:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.contacts.aggregate( [\n { $replaceWith:\n { $mergeObjects:\n [\n { _id: \"\", name: \"\", email: \"\", cell: \"\", home: \"\" },\n \"$$ROOT\"\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">contacts</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">$replaceWith</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$mergeObjects</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">""</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">""</span>, <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">""</span>, <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">""</span>, <span class="lg-highlight-attr">home</span>: <span class="lg-highlight-string">""</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$$ROOT"</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 aggregation returns 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 name: 'Fred',\n email: '[email protected]',\n cell: '',\n home: ''\n},\n{\n _id: 2,\n name: 'Frank N. Stine',\n email: '',\n cell: '012-345-9999',\n home: ''\n},\n{\n _id: 3,\n name: 'Gren Dell',\n email: '[email protected]',\n cell: '',\n home: '987-654-3210'\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>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'Fred'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">'[email protected]'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">''</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">home</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"> <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">name</span>: <span class="lg-highlight-string">'Frank N. Stine'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">''</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">'012-345-9999'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">home</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"> <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">name</span>: <span class="lg-highlight-string">'Gren Dell'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">'[email protected]'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cell</span>: <span class="lg-highlight-string">''</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">home</span>: <span class="lg-highlight-string">'987-654-3210'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/text-search/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Text Search
<a class="headerlink leafygreen-ui-1kepx47" href="#text-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="text-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="#mongodb-atlas-search" target="_self">
<span>
MongoDB Atlas Search
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides different text search capabilities depending on whether
your data is hosted on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self">
<span>
MongoDB Atlas
</span>
</a>
or a self-managed
deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn about search on self-hosted deployments, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/text-search/on-prem/#std-label-text-search-on-prem">
Text Search on Self-Managed Deployments
<!-- -->
.
</a>
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
MongoDB Atlas Search
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-atlas-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="mongodb-atlas-search">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To perform text search on data hosted on MongoDB Atlas, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self">
<span>
MongoDB Atlas Search
</span>
</a>
. Atlas Search supports
fine-grained text indexing and a rich query language for fast, relevant
search results.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more and get started with Atlas Search, see:
</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/reference/atlas-search/query-syntax/" target="_self">
<span>
Atlas Search Aggregation Pipeline Stages
</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/atlas/reference/atlas-search/index-definitions/" target="_self">
<span>
Defining Atlas Search Indexes
</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/atlas/reference/atlas-search/searching/" target="_self">
<span>
Running Atlas Search Queries
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/" target="_self">
<span>
Atlas Search
</span>
</a>
also offers common
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/analyzers/" target="_self">
<span>
analyzers for parsing text for full-text search
</span>
</a>
, including support for over
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/atlas-search/analyzers/language/" target="_self">
<span>
40 language-specific analyzers
<!-- -->
.
</span>
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/query/where/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$where
<a class="headerlink leafygreen-ui-1kepx47" href="#-where" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-where">
</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-x9koo9" href="#available-javascript-properties-and-functions" target="_self">
<span>
Available JavaScript Properties and Functions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#elemmatch" target="_self">
<span>
<code class="css-1kekw28 e1wawog0">
elemMatch
</code>
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#javascript-enablement" target="_self">
<span>
JavaScript Enablement
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#unsupported-array-and-string-functions" target="_self">
<span>
Unsupported Array and String Functions
</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="query">
<dt>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-query-op.-where" 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.-where">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Server-side JavaScript Deprecated
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, server-side JavaScript functions
(
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
) are
deprecated. MongoDB logs a warning when you run these functions.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
operator to pass either a string
containing a JavaScript expression or a full JavaScript function to
the query system. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
provides greater
flexibility, but requires that the database processes the
JavaScript expression or function for
<em>
each
</em>
document in the
collection. Reference the document in the JavaScript expression or
function using either
<code class="leafygreen-ui-1l06pbn">
this
</code>
or
<code class="leafygreen-ui-1l06pbn">
obj
</code>
.
</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">
$where
</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-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
operator has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $where: <string|javascript> }","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">$where</span>: <span class="lg-highlight-xml"><string|JavaScript Code> }</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
no longer supports the deprecated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON type
</a>
JavaScript code with scope (BSON Type 15).
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
operator only supports BSON type String (BSON Type 2) or
BSON type JavaScript (BSON Type 13). The use of BSON type JavaScript with
scope for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
has been deprecated since MongoDB 4.2.1.
</p>
</div>
</div>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Aggregation Alternatives Preferred
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
operator allows the use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggregation expressions
</a>
within
the query language. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
allows users to define custom aggregation expressions
in JavaScript if the provided
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation-pipeline/#std-label-aggregation-pipeline-operator-reference">
pipeline operators
</a>
cannot fulfill your application's needs.
</p>
<p class="leafygreen-ui-1kp3ins">
Given the available aggregation operators:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
with aggregation operators that do not
use JavaScript (i.e. non-
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
and
non-
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
operators) is faster than
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
because it does not execute JavaScript and should
be preferred if possible.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
However, if you must create custom expressions,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
is preferred over
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
.
</span>
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Available JavaScript Properties and Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#available-javascript-properties-and-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="available-javascript-properties-and-functions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
map-reduce operations
</code>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
operator expressions
<strong>
cannot
</strong>
access certain global functions or
properties, such as
<code class="leafygreen-ui-1l06pbn">
db
</code>
, that are available 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">
The following JavaScript functions and properties
<strong>
are available
</strong>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
map-reduce operations
</code>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
operator expressions:
</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>
Available Properties
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Available Functions
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
args
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
assert()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
BinData()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
DBPointer()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
DBRef()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
doassert()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
emit()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
gc()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
HexData()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
hex_md5()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
isNumber()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
isObject()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
ISODate()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
isString()
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
Map()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
MD5()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
NumberInt()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
NumberLong()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
ObjectId()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
print()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
printjson()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
printjsononeline()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
sleep()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
Timestamp()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
tojson()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
tojsononeline()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
tojsonObject()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
UUID()
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
version()
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
elemMatch
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#elemmatch" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="elemmatch">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Only apply the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
query operator to top-level
documents. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
query operator will not work inside a
nested document, for instance, in an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch">
<code class="leafygreen-ui-1l06pbn">
$elemMatch
</code>
</a>
query.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Do not use global variables.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
evaluates JavaScript and cannot take
advantage of indexes. Therefore, query performance improves
when you express your query using the standard MongoDB
operators (e.g.,
<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/in/#mongodb-query-op.-in">
<code class="leafygreen-ui-1l06pbn">
$in
</code>
</a>
).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In general, you should use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
only when you
cannot express your query using another operator. If you must
use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
, try to include at least one other
standard query operator to filter the result set. Using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
alone requires a collection scan.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Using normal non-
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
query statements provides the
following performance advantages:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB will evaluate non-
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
components of query
before
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
statements. If the
non-
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
statements match no documents, MongoDB
will not perform any query evaluation using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The non-
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
query statements may use an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-index">
index
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
JavaScript Enablement
<a class="headerlink leafygreen-ui-1kepx47" href="#javascript-enablement" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="javascript-enablement">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
(or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
, or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
), you must have
server-side scripting enabled (default).
</p>
<p class="leafygreen-ui-1kp3ins">
However, if you do not use these operations, disable server-side
scripting:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.javascriptEnabled">
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
</a>
configuration option or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--noscripting">
<code class="leafygreen-ui-1l06pbn">
--noscripting
</code>
</a>
command-line option.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For 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, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-security.javascriptEnabled">
<code class="leafygreen-ui-1l06pbn">
security.javascriptEnabled
</code>
</a>
configuration option or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-option-mongos.--noscripting">
<code class="leafygreen-ui-1l06pbn">
--noscripting
</code>
</a>
command-line option.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See also
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist-javascript">
➤
<!-- -->
Run MongoDB with Secure Configuration Options
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unsupported Array and String Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#unsupported-array-and-string-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unsupported-array-and-string-functions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 6.0 upgrades the internal JavaScript engine used for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/server-side-javascript/#std-label-server-side-javascript">
server-side JavaScript
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
, and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
expressions and from MozJS-60 to MozJS-91. Several deprecated,
non-standard array and string functions that existed in MozJS-60 are
removed in MozJS-91.
</p>
<p class="leafygreen-ui-1kp3ins">
For the complete list of removed array and string functions, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/6.0-compatibility/#std-label-6.0-js-engine-change">
6.0 compatibility notes
<!-- -->
.
</a>
</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">
Consider the following documents in the
<code class="leafygreen-ui-1l06pbn">
players
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.players.insertMany([\n { _id: 12378, name: \"Steve\", username: \"steveisawesome\", first_login: \"2017-01-01\" },\n { _id: 2, name: \"Anya\", username: \"anya\", first_login: \"2001-02-02\" }\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">players</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">12378</span>, <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Steve"</span>, <span class="lg-highlight-attr">username</span>: <span class="lg-highlight-string">"steveisawesome"</span>, <span class="lg-highlight-attr">first_login</span>: <span class="lg-highlight-string">"2017-01-01"</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">name</span>: <span class="lg-highlight-string">"Anya"</span>, <span class="lg-highlight-attr">username</span>: <span class="lg-highlight-string">"anya"</span>, <span class="lg-highlight-attr">first_login</span>: <span class="lg-highlight-string">"2001-02-02"</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 example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
</span>
</a>
and the
<code class="leafygreen-ui-1l06pbn">
hex_md5()
</code>
JavaScript function to compare the value of the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field to an
MD5 hash and returns any matching document.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.players.find( { $where: function() {\n return (hex_md5(this.name) == \"9b53e667f30cd329dca1ec9e6a83e994\")\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">db.players.find( { <span class="lg-highlight-variable">$where</span>: <span class="lg-highlight-title lg-highlight-function lg-highlight-function">function</span>() {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-built_in">return</span> (hex_md5(this.name) == <span class="lg-highlight-string">"9b53e667f30cd329dca1ec9e6a83e994"</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 result:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 2,\n \"name\" : \"Anya\",\n \"username\" : \"anya\",\n \"first_login\" : \"2001-02-02\"\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> : 2,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> : <span class="lg-highlight-string">"Anya"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"username"</span> : <span class="lg-highlight-string">"anya"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"first_login"</span> : <span class="lg-highlight-string">"2001-02-02"</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">
As an alternative, the previous example can be rewritten using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</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>
. You can define custom aggregation
expression in JavaScript with the aggregation operator
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
.
To access
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
and other aggregation operators in
<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 with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.players.find( {$expr: { $function: {\n body: function(name) { return hex_md5(name) == \"9b53e667f30cd329dca1ec9e6a83e994\"; },\n args: [ \"$name\" ],\n lang: \"js\"\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">players</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{<span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$function</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">body</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">name</span>)<!-- --> <!-- -->{ <span class="lg-highlight-keyword">return</span> <span class="lg-highlight-title lg-highlight-function">hex_md5</span>(<!-- -->name) <!-- -->== <span class="lg-highlight-string">"9b53e667f30cd329dca1ec9e6a83e994"</span>; <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">args</span>: <!-- -->[ <span class="lg-highlight-string">"$name"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lang</span>: <span class="lg-highlight-string">"js"</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 you must create custom expressions,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/function/#mongodb-expression-exp.-function">
<code class="leafygreen-ui-1l06pbn">
$function
</code>
</a>
is
preferred over
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-query-op.-where" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$where
</code>
.
</span>
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/WriteResult/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
WriteResult()
<a class="headerlink leafygreen-ui-1kepx47" href="#writeresult--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="writeresult--">
</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="#properties" target="_self">
<span>
Properties
</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">
WriteResult()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-WriteResult" 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-WriteResult">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A wrapper that contains the result status of
<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>
write methods.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See:
</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.insert/#mongodb-method-db.collection.insert">
<code class="leafygreen-ui-1l06pbn">
db.collection.insert()
</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.update/#mongodb-method-db.collection.update">
<code class="leafygreen-ui-1l06pbn">
db.collection.update()
</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.remove/#mongodb-method-db.collection.remove">
<code class="leafygreen-ui-1l06pbn">
db.collection.remove()
</code>
</a>
</p>
</li>
</ul>
</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insert/#mongodb-method-db.collection.insert">
<code class="leafygreen-ui-1l06pbn">
db.collection.insert()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#mongodb-method-db.collection.update">
<code class="leafygreen-ui-1l06pbn">
db.collection.update()
</code>
</a>
are deprecated.
</p>
<p class="leafygreen-ui-1kp3ins">
The results returned by the replacement methods have a different
format. For output similar to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-WriteResult" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
WriteResult()
</code>
</span>
</a>
, consider
using
<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>
</div>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Properties
<a class="headerlink leafygreen-ui-1kepx47" href="#properties" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="properties">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-WriteResult" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
WriteResult()
</code>
</span>
</a>
has the following properties:
</p>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nInserted
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.nInserted" 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-WriteResult.nInserted">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of documents inserted, excluding
<code class="leafygreen-ui-1l06pbn">
upserted
</code>
documents.
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-WriteResult.nUpserted" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nUpserted
</code>
</span>
</a>
for the number of documents
inserted through an upsert.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nMatched
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.nMatched" 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-WriteResult.nMatched">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of documents selected for update. If the update operation
results in no change to the document, e.g.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
expression
updates the value to the current value,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-WriteResult.nMatched" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nMatched
</code>
</span>
</a>
can be greater than
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-WriteResult.nModified" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nModified
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nModified
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.nModified" 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-WriteResult.nModified">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of existing documents updated. If the update/replacement
operation results in no change to the document, such as setting the
value of the field to its current value,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-WriteResult.nModified" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nModified
</code>
</span>
</a>
can be less than
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-data-WriteResult.nMatched" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
nMatched
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nUpserted
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.nUpserted" 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-WriteResult.nUpserted">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of documents inserted by an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-parameter">
upsert
<!-- -->
.
</a>
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult._id
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult._id" 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-WriteResult._id">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
of the document inserted by an
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
. Returned only
if an
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
results in an insert.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.nRemoved
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.nRemoved" 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-WriteResult.nRemoved">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The number of documents removed.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeError
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeError" 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-WriteResult.writeError">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A document that contains information regarding any error, excluding
write concern errors, encountered during the write operation.
</p>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeError.code
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeError.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-WriteResult.writeError.code">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
An integer value identifying the error.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeError.errmsg
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeError.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-WriteResult.writeError.errmsg">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A description of the error.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeError.errInfo
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeError.errInfo" 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-WriteResult.writeError.errInfo">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A document that contains information regarding any write errors,
excluding write concern errors, that were encountered during the
write operation. When an operation fails document validation, the
server produces an error under this field explaining why the
document did not match against the collection's validator
expression.
</p>
</dd>
</dl>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeConcernError
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeConcernError" 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-WriteResult.writeConcernError">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Document describing errors that relate to the write concern.
</p>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
7.1
</em>
:
<!-- -->
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-method-WriteResult">
<code class="leafygreen-ui-1l06pbn">
WriteResult()
</code>
</a>
is received from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#std-program-mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
, write concern
errors are always reported, even when one or more write
errors occur.
</p>
<p class="leafygreen-ui-1kp3ins">
In previous releases, the occurrence of write errors could
cause the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-WriteResult" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
WriteResult()
</code>
</span>
</a>
to not report write concern errors.
</p>
</div>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeConcernError.code
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeConcernError.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-WriteResult.writeConcernError.code">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
An integer value identifying the cause of the write concern error.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeConcernError.errmsg
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeConcernError.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-WriteResult.writeConcernError.errmsg">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A description of the cause of the write concern error.
</p>
</dd>
</dl>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeConcernError.errInfo.writeConcern
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeConcernError.errInfo.writeConcern" 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-WriteResult.writeConcernError.errInfo.writeConcern">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The write concern object used for the corresponding operation. For
information on write concern object fields, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-specs">
Write Concern Specification
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The write concern object may also contain the following field,
indicating the source of the write concern:
</p>
<dl class="data">
<dt>
<code class="leafygreen-ui-1l06pbn">
WriteResult.writeConcernError.errInfo.writeConcern.provenance
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-data-WriteResult.writeConcernError.errInfo.writeConcern.provenance" 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-WriteResult.writeConcernError.errInfo.writeConcern.provenance">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
A string value indicating where the write concern originated (known as
write concern
<code class="leafygreen-ui-1l06pbn">
provenance
</code>
). The following table shows the possible
values for this field 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 write 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 write 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">
getLastErrorDefaults
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The write concern originated from the replica set's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.getLastErrorDefaults">
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorDefaults
</code>
</a>
field.
</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 write concern originated from the server in absence
of all other write concern specifications.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</dd>
</dl>
</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/method/WriteResult.hasWriteError/#mongodb-method-WriteResult.hasWriteError">
<code class="leafygreen-ui-1l06pbn">
WriteResult.hasWriteError()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult.hasWriteConcernError/#mongodb-method-WriteResult.hasWriteConcernError">
<code class="leafygreen-ui-1l06pbn">
WriteResult.hasWriteConcernError()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/enable-qe/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Enabling Queryable Encryption when Creating Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#enabling-queryable-encryption-when-creating-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="enabling-queryable-encryption-when-creating-collections">
</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="#enable-queryable-encryption-on-a-collection" target="_self">
<span>
Enable Queryable Encryption on a Collection
</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">
Enable Queryable Encryption at collection creation. You can't encrypt fields on
documents that are already in a collection.
</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">
Explicitly create your collection, rather than creating it implicitly
with an insert operation. When you create a collection using
<code class="leafygreen-ui-1l06pbn">
createCollection()
</code>
, MongoDB creates an index on the encrypted
fields. Without this index, queries on encrypted fields may run
slowly.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Enable Queryable Encryption on a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-queryable-encryption-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-queryable-encryption-on-a-collection">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can enable Queryable Encryption on fields in one of two ways. The following
examples use Node.js to enable Queryable Encryption:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Pass the encryption schema, represented by the
<code class="leafygreen-ui-1l06pbn">
encryptedFieldsObject
</code>
constant, to the client that the application uses to create the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"const client = new MongoClient(uri, {\n autoEncryption: {\n keyVaultNameSpace: \"<your>\",\n kmsProviders: \"<your>\",\n extraOptions: {\n cryptSharedLibPath: \"<path>\"\n },\n encryptedFieldsMap: {\n \"<databasename.collectionname>\": { encryptedFieldsObject }\n }\n }\n\n ...\n\n await client.db(\"<database>\").createEncryptedCollection(\"<collection>\");\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">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-attr">autoEncryption</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyVaultNameSpace</span>: <span class="lg-highlight-string">"<your keyvault namespace>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">kmsProviders</span>: <span class="lg-highlight-string">"<your kms provider>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">extraOptions</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cryptSharedLibPath</span>: <span class="lg-highlight-string">"<path to Automatic Encryption Shared Library>"</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">encryptedFieldsMap</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<databaseName.collectionName>"</span>: <!-- -->{ <!-- -->encryptedFieldsObject }</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"><div class="leafygreen-ui-ihxujy"></div></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">db</span>(<span class="lg-highlight-string">"<database name>"</span>).<span class="lg-highlight-title lg-highlight-function">createEncryptedCollection</span>(<span class="lg-highlight-string">"<collection name>"</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">
For more information on
<code class="leafygreen-ui-1l06pbn">
autoEncryption
</code>
configuration options, see the
section on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/qe-options-clients/#std-label-qe-reference-mongo-client">
MongoClient Options for Queryable Encryption
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Pass the encryption schema
<code class="leafygreen-ui-1l06pbn">
encryptedFieldsObject
</code>
to
<code class="leafygreen-ui-1l06pbn">
createEncryptedCollection()
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"await encryptedDB.createEncryptedCollection(\"<collection>\", {\n encryptedFields: encryptedFieldsObject\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">await</span> encryptedDB.<span class="lg-highlight-title lg-highlight-function">createEncryptedCollection</span>(<span class="lg-highlight-string">"<collection name>"</span>, <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">encryptedFields</span>: <!-- -->encryptedFieldsObject</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>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Specify the
<code class="leafygreen-ui-1l06pbn">
encryptedFieldsObject
</code>
when you create the
collection, and also when you create a client to access the
collection. This ensures that if the server's security is
compromised, the information is still encrypted through the client.
</p>
</div>
</div>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/csfle/reference/limitations/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
CSFLE Limitations
<a class="headerlink leafygreen-ui-1kepx47" href="#csfle-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="csfle-limitations">
</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="#read-and-write-operation-support" target="_self">
<span>
Read and Write Operation Support
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#arrays" target="_self">
<span>
Arrays
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#views" target="_self">
<span>
Views
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#collation" target="_self">
<span>
Collation
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#unique-indexes" target="_self">
<span>
Unique Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#shard-key" target="_self">
<span>
Shard Key
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#read-write-query-support" target="_self">
<span>
Read/Write Query Support
</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">
Consider these limitations and restrictions before you enable CSFLE.
Some operations are unsupported, and others behave differently.
</p>
<p class="leafygreen-ui-1kp3ins">
For compatibility limitations, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/reference/compatibility/#std-label-qe-csfle-compatibility">
Compatibility
<!-- -->
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read and Write Operation Support
<a class="headerlink leafygreen-ui-1kepx47" href="#read-and-write-operation-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="read-and-write-operation-support">
</div>
</a>
</h2>
<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>
only stores encrypted
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_binary">
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
</a>
and applies any aggregation expression or query operator
specifying an encrypted field against the
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
value. While the
expression or operator may support
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
fields, the resulting
value may be incorrect or unexpected when compared to issuing that same
expression or operator against the decrypted value. The
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
throws an error if the expression or operator does not support
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, consider a deterministically encrypted integer
<code class="leafygreen-ui-1l06pbn">
Salary
</code>
.
A query filters for documents where
<code class="leafygreen-ui-1l06pbn">
Salary
</code>
is greater than
<code class="leafygreen-ui-1l06pbn">
100000
</code>
. The application explicitly (manually) encrypts the query
value using deterministic encryption prior to issuing the query. The
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
compares the
<em>
encrypted
</em>
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
value of
<code class="leafygreen-ui-1l06pbn">
100000
</code>
to
the
<em>
encrypted
</em>
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
values stored in each document. While the
operation returns successfully, the comparison of the
<code class="leafygreen-ui-1l06pbn">
BinData
</code>
values
may return a different result than the comparison of the decrypted
integer values.
</p>
<p class="leafygreen-ui-1kp3ins">
Automatic Client-Side Field Level Encryption rejects read or write
operations which would return incorrect or unexpected results when
issued against an encrypted field. For complete documentation, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
Supported Operations for Automatic Encryption
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Applications performing explicit (manual) encryption may reference the
linked page as guidance for issuing read/write operations against
encrypted fields.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Arrays
<a class="headerlink leafygreen-ui-1kepx47" href="#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="arrays">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
CSFLE does not support automatic encryption on fields within an array of documents.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Views
<a class="headerlink leafygreen-ui-1kepx47" href="#views" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="views">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Queries against
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
views
</a>
on collections
containing values encrypted with Client-Side Field Level Encryption may return
unexpected or incorrect results if either the underlying view
aggregation pipeline
<em>
or
</em>
the query references encrypted fields. If
creating a view on a collection containing values encrypted with Client-Side Field Level Encryption,
avoid operating on encrypted fields to mitigate the
risk of unexpected or incorrect results.
</p>
<p class="leafygreen-ui-1kp3ins">
While 4.2+ compatible drivers configured for automatic Client-Side Field Level Encryption have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
supported operations for automatic encryption
</a>
,
for unsupported read and write operations, the underlying support library
cannot introspect the view catalog to identify a given collection as a
view. Applications therefore cannot rely on the automatic Client-Side Field Level Encryption
validation to prevent unsupported queries against views on
collections with encrypted fields.
</p>
<p class="leafygreen-ui-1kp3ins">
For applications using explicit (manual) encryption to query a view on a
collection containing encrypted values, consider constructing the query
using
<em>
only
</em>
query operators with known
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-supported-query-operators">
normal behavior
</a>
when issued against encrypted fields.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Collation
<a class="headerlink leafygreen-ui-1kepx47" href="#collation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Client-Side Field Level Encryption does not respect user-specified
collations or collection default
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields">
collations
</a>
.
Field level encryption obscures the field value
and prevents normal collation behavior. Collation-sensitive queries
against encrypted fields may return unexpected or incorrect results.
</p>
<p class="leafygreen-ui-1kp3ins">
While 4.2+ compatible drivers configured for automatic Client-Side Field Level Encryption have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
supported operations for automatic encryption
</a>
,
for unsupported read and write operations the underlying support library
cannot introspect the collection catalog to identify the default
collation. Applications therefore cannot rely on the Client-Side Field Level Encryption
validation to prevent querying on encrypted fields with
collation defaults.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Unique Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#unique-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="unique-indexes">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
Unique indexes
</a>
<em>
cannot
</em>
guarantee
uniqueness if the index key specifies any
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/fundamentals/encryption-algorithms/#std-label-csfle-random-encryption">
randomly encrypted
</a>
fields.
</p>
<p class="leafygreen-ui-1kp3ins">
Fields encrypted using the random algorithm
<em>
always
</em>
produce a different
encrypted value given a specific
input. The server considers each encrypted value unique even though the
decrypted value itself is not unique. The collection can therefore
contain multiple documents with duplicate decrypted values for a field
with an index-enforced unique constraint.
</p>
<p class="leafygreen-ui-1kp3ins">
While 4.2+ compatible drivers configured for automatic Client-Side Field Level Encryption have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
supported operations for automatic encryption
</a>
for unsupported read and write operations, the underlying support library
cannot introspect the index catalog to identify a given field as unique.
Applications therefore cannot rely on the automatic Client-Side Field Level Encryption
validation to prevent unique constraint violations on
randomly-encrypted fields.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-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="shard-key">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Specifying a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key">
shard key
</a>
on encrypted fields
<em>
or
</em>
encrypting fields of an existing shard key may result in unexpected or
incorrect sharding behavior.
</p>
<p class="leafygreen-ui-1kp3ins">
While 4.2+ compatible drivers configured for automatic Client-Side Field Level Encryption have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
supported operations for automatic encryption
</a>
,
for unsupported read and write operations, the underlying support library
cannot introspect the sharding catalog metadata to identify shard key
fields. Applications therefore cannot rely on the automatic field level
encryption validation to prevent encryption of shard key fields.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Read/Write Query Support
<a class="headerlink leafygreen-ui-1kepx47" href="#read-write-query-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="read-write-query-support">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Automatic Client-Side Field Level Encryption supports a subset of
commands, query operators, update operators, aggregation stages, and
aggregation expressions. For complete documentation, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/supported-operations/#std-label-csfle-reference-automatic-encryption-supported-operations">
Supported Operations for Automatic Encryption
<!-- -->
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/aggregation-pipeline-sharded-collections/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Aggregation Pipeline and Sharded Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-pipeline-and-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="aggregation-pipeline-and-sharded-collections">
</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="#optimization" target="_self">
<span>
Optimization
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The aggregation pipeline supports operations on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded
</a>
collections. This section describes behaviors
specific to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
</a>
and
sharded collections.
</p>
<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 pipeline starts with an exact
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/match/#mongodb-pipeline-pipe.-match">
<code class="leafygreen-ui-1l06pbn">
$match
</code>
</a>
on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
, and the pipeline does not contain
<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/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
stages, the entire pipeline runs on the matching
shard only.
</p>
<p class="leafygreen-ui-1kp3ins">
When aggregation operations run on multiple shards, the results are
routed to 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 be merged, except in the
following cases:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the pipeline includes 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, the merge runs
on the shard where the output collection lives.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the pipeline includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
stage that references
an unsharded collection, the merge runs on the shard where the
unsharded collection lives.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the pipeline includes a sorting or grouping stage, and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/aggregate/#std-label-aggregate-cmd-allowDiskUse">
allowDiskUse
</a>
setting is enabled,
the merge runs on a randomly-selected shard.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Optimization
<a class="headerlink leafygreen-ui-1kepx47" href="#optimization" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="optimization">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When splitting the aggregation pipeline into two parts, the pipeline is
split to ensure that the shards perform as many stages as possible with
consideration for optimization.
</p>
<p class="leafygreen-ui-1kp3ins">
To see how the pipeline was split, include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
explain
</code>
</a>
option in the
<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>
method.
</p>
<p class="leafygreen-ui-1kp3ins">
Optimizations are subject to change between releases.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-enterprise-on-amazon/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Install MongoDB Enterprise Edition on Amazon Linux
<a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-enterprise-edition-on-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="install-mongodb-enterprise-edition-on-amazon-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="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#install-mongodb-enterprise-edition" target="_self">
<span>
Install MongoDB Enterprise Edition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#run-mongodb-enterprise-edition" target="_self">
<span>
Run MongoDB Enterprise Edition
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#uninstall-mongodb" target="_self">
<span>
Uninstall MongoDB
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-information" target="_self">
<span>
Additional Information
</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">
Use this tutorial to install MongoDB 8.0
<!-- -->
Enterprise
<!-- -->
Edition
on Amazon Linux using the
<code class="leafygreen-ui-1l06pbn">
yum
</code>
package manager.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/products/mongodb-enterprise-advanced?tck=docs_server" target="_self">
<span>
MongoDB Enterprise Edition
</span>
</a>
is available on select platforms and contains support for several
features related to security and monitoring.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Verify Linux Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-linux-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="verify-linux-distribution">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can verify which Linux distribution you are running by running the
following command on the command-line:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"grep ^NAME /etc/*release"}
</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">grep ^NAME /etc/*release</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 should be
<strong>
Amazon Linux
</strong>
or
<strong>
Amazon Linux AMI
</strong>
. If using
a different Linux distribution, please see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/install-enterprise-linux/#std-label-install-enterprise-linux">
install instructions for your platform
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
MongoDB Version
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-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="mongodb-version">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This tutorial installs MongoDB 8.0
<!-- -->
Enterprise
<!-- -->
Edition. To install a different version of MongoDB
<!-- -->
Enterprise
<!-- -->
,
use the version drop-down menu in the upper-left corner of this page to
select the documentation for that version.
</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">
Platform Support
<a class="headerlink leafygreen-ui-1kepx47" href="#platform-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="platform-support">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB 8.0 Enterprise Edition supports the following
<strong class="css-4dei7l">
64-bit
</strong>
Amazon Linux release on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-x86_64">
x86_64
</a>
architecture:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Amazon Linux 2023
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
MongoDB only supports the 64-bit versions of this platform.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB 8.0 Enterprise Edition on Amazon Linux also supports the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms-ARM64">
ARM64
</a>
architecture on
select platforms.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/#std-label-prod-notes-supported-platforms">
Platform Support
</a>
for more information.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Production Notes
<a class="headerlink leafygreen-ui-1kepx47" href="#production-notes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-notes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Before deploying MongoDB in a production environment, consider the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/production-notes/">
Production Notes for Self-Managed Deployments
</a>
document which offers
performance considerations and configuration recommendations for
production MongoDB deployments.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Install MongoDB Enterprise Edition
<a class="headerlink leafygreen-ui-1kepx47" href="#install-mongodb-enterprise-edition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-mongodb-enterprise-edition">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Follow these steps to install MongoDB
<!-- -->
Enterprise
<!-- -->
Edition using the
<code class="leafygreen-ui-1l06pbn">
yum
</code>
package manager. Select the tab for your version of
Amazon Linux:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Configure the package management system (yum).Create an /etc/yum.repos.d/mongodb-enterprise-8.0.repo file so that\nyou can install MongoDB enterprise directly using yum:If you have a mongodb-enterprise.repo file\nin this directory from a previous installation of MongoDB, you\nshould remove it. Use the mongodb-enterprise-8.0.repo\nfile above to install MongoDB 8.0.You can also download the .rpm files directly from the\nMongoDB repository.\nDownloads are organized by Amazon Linux\nversion (e.g. 2023), then MongoDB\nrelease version\n(e.g. 8.0), then architecture (e.g. x86_64)."},{"@type":"HowToStep","text":"To install the latest stable version of MongoDB Enterprise\n8.0, issue the following command:To install a specific release, you must specify each component package\nindividually along with the version number, as in the\nfollowing example:Although you can specify any available version of MongoDB\nEnterprise, yum upgrades the packages when a newer\nversion becomes available. To prevent unintended upgrades,\npin the package by adding the following exclude directive\nto your /etc/yum.conf file:"}],"name":"Install MongoDB Enterprise Edition","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 the package management system (
<code class="leafygreen-ui-1l06pbn">
yum
</code>
).
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-the-package-management-system-yum" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-package-management-system-yum">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an
<code class="leafygreen-ui-1l06pbn">
/etc/yum.repos.d/mongodb-enterprise-8.0.repo
</code>
file so that
you can install MongoDB enterprise directly using
<code class="leafygreen-ui-1l06pbn">
yum
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[mongodb-enterprise-8.0]\nname=MongoDB Enterprise Repository\nbaseurl=https://repo.mongodb.com/yum/amazon/2023/mongodb-enterprise/8.0/$basearch/\ngpgcheck=1\nenabled=1\ngpgkey=https://pgp.mongodb.com/server-8.0.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">[mongodb-enterprise-8.0]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">name=MongoDB Enterprise Repository</td></tr><tr class=""><td class="leafygreen-ui-7razhx">baseurl=https://repo.mongodb.com/yum/amazon/2023/mongodb-enterprise/8.0/$basearch/</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/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>
<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 you have a
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise.repo
</code>
file
in this directory from a previous installation of MongoDB, you
should remove it. Use the
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise-8.0.repo
</code>
file above to install MongoDB 8.0.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can also download the
<code class="leafygreen-ui-1l06pbn">
.rpm
</code>
files directly from the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://repo.mongodb.com/yum/amazon/" target="_self">
<span>
MongoDB repository
</span>
</a>
.
Downloads are organized by Amazon Linux
version (e.g.
<code class="leafygreen-ui-1l06pbn">
2023
</code>
), then MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/versioning/#std-label-release-version-numbers">
release version
</a>
(e.g.
<code class="leafygreen-ui-1l06pbn">
8.0
</code>
), then architecture (e.g.
<code class="leafygreen-ui-1l06pbn">
x86_64
</code>
).
</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>
<p class="leafygreen-ui-1kp3ins">
To install the latest stable version of MongoDB Enterprise
8.0, issue the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise","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 mongodb-enterprise</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 install a specific release, you must specify each component package
individually along with the version number, as in the
following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-8.0.0 mongodb-enterprise-database-8.0.0 mongodb-enterprise-server-8.0.0 mongodb-mongosh mongodb-enterprise-mongos-8.0.0 mongodb-enterprise-tools-8.0.0\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">sudo yum install -y mongodb-enterprise-8.0.0 mongodb-enterprise-database-8.0.0 mongodb-enterprise-server-8.0.0 mongodb-mongosh mongodb-enterprise-mongos-8.0.0 mongodb-enterprise-tools-8.0.0</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Although you can specify any available version of MongoDB
Enterprise,
<code class="leafygreen-ui-1l06pbn">
yum
</code>
upgrades the packages when a newer
version becomes available. To prevent unintended upgrades,
pin the package by adding the following
<code class="leafygreen-ui-1l06pbn">
exclude
</code>
directive
to your
<code class="leafygreen-ui-1l06pbn">
/etc/yum.conf
</code>
file:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"exclude=mongodb-enterprise,mongodb-enterprise-database,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools","programmingLanguage":"Ini"}
</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 ini leafygreen-ui-9ybzas"><table class="leafygreen-ui-1tr4g10"><tbody><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-attr">exclude</span>=mongodb-enterprise,mongodb-enterprise-database,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,mongodb-enterprise-tools</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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>
</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">
You can also install the MongoDB Shell that uses the system's OpenSSL.
You must have already installed OpenSSL on your system before
installing this version of the MongoDB Shell.
</p>
<p class="leafygreen-ui-1kp3ins">
You can install all of the MongoDB Enterprise packages and the
MongoDB Shell that uses the system's OpenSSL without removing the
MongoDB Shell first. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise mongodb-mongosh-shared-openssl11","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 yum install -y mongodb-enterprise mongodb-mongosh-shared-openssl11</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 removes the MongoDB Shell and then installs the
MongoDB Shell that uses the system's OpenSSL 1.1:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum remove -y mongodb-mongosh && sudo yum install -y\nmongodb-mongosh-shared-openssl11","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">sudo yum remove -y mongodb-mongosh && sudo yum install -y</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-mongosh-shared-openssl11</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 removes the MongoDB Shell and then installs the
MongoDB Shell that uses the system's OpenSSL 3:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum remove -y mongodb-mongosh && sudo yum install -y\nmongodb-mongosh-shared-openssl3","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">sudo yum remove -y mongodb-mongosh && sudo yum install -y</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-mongosh-shared-openssl3</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 also choose the MongoDB packages to install.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example installs MongoDB Enterprise and tools, and the
MongoDB Shell that uses the system's OpenSSL 1.1:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-database\nmongodb-enterprise-tools mongodb-mongosh-shared-openssl11","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">sudo yum install -y mongodb-enterprise-database</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-enterprise-tools mongodb-mongosh-shared-openssl11</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 installs MongoDB Enterprise and tools, and the
MongoDB Shell that uses the system's OpenSSL 3:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum install -y mongodb-enterprise-database\nmongodb-enterprise-tools mongodb-mongosh-shared-openssl3","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">sudo yum install -y mongodb-enterprise-database</td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongodb-enterprise-tools mongodb-mongosh-shared-openssl3</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Run MongoDB Enterprise Edition
<a class="headerlink leafygreen-ui-1kepx47" href="#run-mongodb-enterprise-edition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="run-mongodb-enterprise-edition">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
ulimit Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#ulimit-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="ulimit-considerations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Most Unix-like operating systems limit the system resources that a
process may use. These limits may negatively impact MongoDB operation,
and should be adjusted. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/ulimit/">
UNIX
<code class="leafygreen-ui-1l06pbn">
ulimit
</code>
Settings for Self-Managed Deployments
</a>
for the recommended
settings for your platform.
</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">
ulimit
</code>
value for number of open files is under
<code class="leafygreen-ui-1l06pbn">
64000
</code>
, MongoDB
generates a startup warning.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Directories
<a class="headerlink leafygreen-ui-1kepx47" href="#directories" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="directories">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, a MongoDB instance stores:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
its data files in
<code class="leafygreen-ui-1l06pbn">
/var/lib/mongo
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
its log files in
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you installed via the package manager, these default directories are
created during the installation.
</p>
<p class="leafygreen-ui-1kp3ins">
If you installed manually by downloading the tarballs, you can create
the directories using
<code class="leafygreen-ui-1l06pbn">
mkdir -p <directory>
</code>
or
<code class="leafygreen-ui-1l06pbn">
sudo mkdir -p
<directory>
</code>
depending on the user that will run MongoDB. (See your
linux man pages for information on
<code class="leafygreen-ui-1l06pbn">
mkdir
</code>
and
<code class="leafygreen-ui-1l06pbn">
sudo
</code>
.)
</p>
<p class="leafygreen-ui-1kp3ins">
By default, MongoDB runs using the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
user account. If you
change the user that runs the MongoDB process, you
<strong>
must
</strong>
also modify
the permission to the
<code class="leafygreen-ui-1l06pbn">
/var/lib/mongo
</code>
and
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb
</code>
directories to give this user access to these directories.
</p>
<p class="leafygreen-ui-1kp3ins">
To specify a different log file directory and data file directory, edit
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>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-storage.dbPath">
<code class="leafygreen-ui-1l06pbn">
storage.dbPath
</code>
</a>
settings in
the
<code class="leafygreen-ui-1l06pbn">
/etc/mongod.conf
</code>
. Ensure that the user running MongoDB has
access to these directories.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<p class="leafygreen-ui-1kp3ins">
Follow these steps to run MongoDB
<!-- -->
Enterprise
<!-- -->
Edition. These instructions
assume that you are using the default settings.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong>
Init System
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
To run and manage your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
process, you will be using
your operating system's built-in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-init-system">
init system
</a>
. Recent versions of
Linux tend to use
<strong>
systemd
</strong>
(which uses the
<code class="leafygreen-ui-1l06pbn">
systemctl
</code>
command),
while older versions of Linux tend to use
<strong>
System V init
</strong>
(which uses
the
<code class="leafygreen-ui-1l06pbn">
service
</code>
command).
</p>
<p class="leafygreen-ui-1kp3ins">
If you are unsure which init system your platform uses, run the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ps --no-headers -o comm 1","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">ps --no-headers -o <span class="lg-highlight-built_in">comm</span> 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>
<p class="leafygreen-ui-1kp3ins">
Then select the appropriate tab below based on the result:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
systemd
</code>
- select the
<strong>
systemd (systemctl)
</strong>
tab below.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
init
</code>
- select the
<strong>
System V Init (service)
</strong>
tab below.
</p>
</li>
</ul>
<div class="line-block">
<div class="line">
<br/>
</div>
</div>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-26">
<div aria-label="Tabs to describe usage of systemd-systemctl/systemvinit-service" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_di71z7rtp" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_21zd9i0si" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
systemd (systemctl)
</div>
</button>
<button aria-controls="_wi1nb3kjd" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_doy5ldkyv" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
System V Init (service)
</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="_jjk5qd9x9" class="" id="_lxjlhnb0y" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the\nfollowing command:If you receive an error similar to the following when starting\nmongod:Failed to start mongod.service: Unit mongod.service not found.Run the following command first:Then run the start command above again."},{"@type":"HowToStep","text":"Verify that MongoDB has started successfully.You can verify that the mongod process has started\nsuccessfully by issuing the following command:You can optionally ensure that MongoDB will start following a\nsystem reboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - systemd (systemctl)","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">
Start MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#start-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="start-mongodb">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can 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>
process by issuing the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl start mongod\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">sudo systemctl start 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">
If you receive an error similar to the following 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>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Failed to start mongod.service: Unit mongod.service not found.
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Run the following command first:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl daemon-reload\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">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>
<p class="leafygreen-ui-1kp3ins">
Then run the start command above again.
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Verify that MongoDB has started successfully.
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-that-mongodb-has-started-successfully">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can verify that 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 has started
successfully by issuing the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl status mongod\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">sudo systemctl status 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">
You can optionally ensure that MongoDB will start following a
system reboot by issuing the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl enable mongod\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">sudo systemctl enable 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 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">
Stop MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#stop-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="stop-mongodb">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
As needed, you can stop 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 by issuing the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl stop mongod\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">sudo systemctl stop 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 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">
Restart MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-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="restart-mongodb">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can 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>
process by issuing the following
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo systemctl restart mongod\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">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>
<p class="leafygreen-ui-1kp3ins">
You can follow the state of the process for errors or important messages
by watching the output in the
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb/mongod.log
</code>
file.
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Begin using MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-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="begin-using-mongodb">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Start 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 on the same host machine as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. You can run
<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>
without any command-line options to connect to 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 running on your localhost with default
port 27017.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\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">mongosh</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 connecting 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>
,
such as to connect to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance running
on a different host and/or port, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self">
<span>
mongosh documentation
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To help you start using MongoDB, MongoDB provides
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started">
Getting
Started Guides
</a>
in various driver editions. For the
driver documentation, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self">
<span>
Start Developing with MongoDB
<!-- -->
.
</span>
</a>
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_mfknn461t" class="leafygreen-ui-38lglc" id="_e37gbmehx" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Start MongoDB.You can start the mongod process by issuing the following\ncommand:"},{"@type":"HowToStep","text":"Verify that MongoDB has started successfullyYou can verify that the mongod process has started\nsuccessfully by checking the contents of the log file at\n/var/log/mongodb/mongod.log\nfor a line readingwhere <port> is the port configured in /etc/mongod.conf, 27017 by default.You can optionally ensure that MongoDB will start following a system\nreboot by issuing the following command:"},{"@type":"HowToStep","text":"Stop MongoDB.As needed, you can stop the mongod process by issuing the\nfollowing command:"},{"@type":"HowToStep","text":"Restart MongoDB.You can restart the mongod process by issuing the following\ncommand:You can follow the state of the process for errors or important messages\nby watching the output in the /var/log/mongodb/mongod.log file."},{"@type":"HowToStep","text":"Begin using MongoDB.Start a mongosh session on the same host machine as the\nmongod. You can run mongosh\nwithout any command-line options to connect to a\nmongod that is running on your localhost with default\nport 27017.For more information on connecting using mongosh,\nsuch as to connect to a mongod instance running\non a different host and/or port, see the\nmongosh documentation.To help you start using MongoDB, MongoDB provides Getting\nStarted Guides in various driver editions. For the\ndriver documentation, see Start Developing with MongoDB."}],"name":"Procedure - System V Init (service)","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">
Start MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#start-mongodb-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="start-mongodb-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can 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>
process by issuing the following
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod start\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">sudo service mongod start</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Verify that MongoDB has started successfully
<a class="headerlink leafygreen-ui-1kepx47" href="#verify-that-mongodb-has-started-successfully-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="verify-that-mongodb-has-started-successfully-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can verify that 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 has started
successfully by checking the contents of the log file at
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb/mongod.log
</code>
for a line reading
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[initandlisten] waiting for connections on port <port>\n"}
</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">[initandlisten] waiting for connections on port <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>
<p class="leafygreen-ui-1kp3ins">
where
<code class="leafygreen-ui-1l06pbn">
<port>
</code>
is the port configured in
<code class="leafygreen-ui-1l06pbn">
/etc/mongod.conf
</code>
,
<code class="leafygreen-ui-1l06pbn">
27017
</code>
by default.
</p>
<p class="leafygreen-ui-1kp3ins">
You can optionally ensure that MongoDB will start following a system
reboot by issuing the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo chkconfig mongod on\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">sudo chkconfig mongod on</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Stop MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-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="stop-mongodb-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
As needed, you can stop 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 by issuing the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\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">sudo service mongod stop</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Restart MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#restart-mongodb-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="restart-mongodb-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can 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>
process by issuing the following
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod restart\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">sudo service mongod restart</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 follow the state of the process for errors or important messages
by watching the output in the
<code class="leafygreen-ui-1l06pbn">
/var/log/mongodb/mongod.log
</code>
file.
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Begin using MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#begin-using-mongodb-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="begin-using-mongodb-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Start 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 on the same host machine as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
. You can run
<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>
without any command-line options to connect to 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 running on your localhost with default
port 27017.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"\nmongosh\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">mongosh</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 connecting 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>
,
such as to connect to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance running
on a different host and/or port, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self">
<span>
mongosh documentation
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To help you start using MongoDB, MongoDB provides
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/getting-started/#std-label-getting-started">
Getting
Started Guides
</a>
in various driver editions. For the
driver documentation, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://api.mongodb.com/" target="_self">
<span>
Start Developing with MongoDB
<!-- -->
.
</span>
</a>
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Uninstall MongoDB
<a class="headerlink leafygreen-ui-1kepx47" href="#uninstall-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="uninstall-mongodb">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To completely remove MongoDB from a system, you must remove the MongoDB
applications themselves, the configuration files, and any directories containing
data and logs. The following section guides you through the necessary steps.
</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">
This process will
<em>
completely
</em>
remove MongoDB, its configuration, and
<em>
all
</em>
databases. This process is not reversible, so ensure that all of your
configuration and data is backed up before proceeding.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Stop MongoDB.Stop the mongod process by issuing the following command:"},{"@type":"HowToStep","text":"Remove Packages.Remove any MongoDB packages that you had previously installed."},{"@type":"HowToStep","text":"Remove Data Directories.Remove MongoDB databases and log files."}],"name":"Uninstall MongoDB","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">
Stop MongoDB.
<a class="headerlink leafygreen-ui-1kepx47" href="#stop-mongodb-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="stop-mongodb-2">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Stop 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 by issuing the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo service mongod stop\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">sudo service mongod stop</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Remove Packages.
<a class="headerlink leafygreen-ui-1kepx47" href="#remove-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="remove-packages">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Remove any MongoDB packages that you had previously installed.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo yum erase $(sudo rpm -qa | grep mongodb-enterprise)\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">sudo yum erase $(sudo rpm -qa | grep mongodb-enterprise)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Remove Data Directories.
<a class="headerlink leafygreen-ui-1kepx47" href="#remove-data-directories" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-data-directories">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Remove MongoDB databases and log files.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sudo rm -r /var/log/mongodb\nsudo rm -r /var/lib/mongo\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">sudo rm -r /var/log/mongodb</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sudo rm -r /var/lib/mongo</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 Information
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-information">
</div>
</a>
</h2>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Localhost Binding by Default
<a class="headerlink leafygreen-ui-1kepx47" href="#localhost-binding-by-default" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="localhost-binding-by-default">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, MongoDB launches with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
bindIp
</code>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
127.0.0.1
</code>
, which binds to the localhost network interface. This
means that the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
can only accept connections from
clients that are running on the same machine. Remote clients will not be
able to connect to the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
, and the
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
will
not be able to initialize a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
unless this value is set
to a valid network interface.
</p>
<p class="leafygreen-ui-1kp3ins">
This value can be configured either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
in the MongoDB configuration file with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
bindIp
</code>
</a>
, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
via the command-line argument
<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>
</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">
Before you bind your instance to a publicly-accessible IP address,
you must secure your cluster from unauthorized access. For a complete
list of security recommendations, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist">
Security Checklist for Self-Managed Deployments
</a>
. At minimum, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth">
enabling authentication
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening">
hardening
network infrastructure
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on configuring
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.bindIp">
<code class="leafygreen-ui-1l06pbn">
bindIp
</code>
</a>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-mongodb-configuration/">
IP Binding in Self-Managed Deployments
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
MongoDB Enterprise Edition Packages
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-enterprise-edition-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="mongodb-enterprise-edition-packages">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB Enterprise Edition is available from its own dedicated
repository, and contains the following officially-supported packages:
</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">
<tr data-testid="leafygreen-ui-header-row">
<th class="leafygreen-ui-1trtg6r" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Package Name
</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">
mongodb-enterprise
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A
<code class="leafygreen-ui-1l06pbn">
metapackage
</code>
that automatically installs the component
packages listed below.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise-database
</code>
</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">
metapackage
</code>
that automatically installs the component
packages listed below.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:50%"/>
<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>
Package Name
</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">
mongodb-enterprise-server
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
daemon and associated
configuration and init scripts.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise-mongos
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
daemon.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise-cryptd
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/reference/encryption-components/#std-label-csfle-encryption-components">
mongocryptd
</a>
binary
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-mongosh
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the MongoDB Shell (
<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>
).
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-shared-openssl*
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the MongoDB Shell that uses the OpenSSL version already
installed on your computer (
<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>
).
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mongodb-enterprise-tools
</code>
</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">
metapackage
</code>
that automatically installs the component
packages listed below:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:50%"/>
<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>
Package Name
</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">
mongodb-database-tools
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Contains the following MongoDB database tools:
</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/database-tools/mongodump/#mongodb-binary-bin.mongodump" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongodump
</code>
</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/database-tools/mongorestore/#mongodb-binary-bin.mongorestore" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongorestore
</code>
</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/database-tools/bsondump/#mongodb-binary-bin.bsondump" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
bsondump
</code>
</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/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoimport
</code>
</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/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoexport
</code>
</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/database-tools/mongostat/#mongodb-binary-bin.mongostat" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongostat
</code>
</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/database-tools/mongotop/#mongodb-binary-bin.mongotop" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongotop
</code>
</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/database-tools/mongofiles/#mongodb-binary-bin.mongofiles" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongofiles
</code>
</span>
</a>
</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">
mongodb-enterprise-database-tools-extra
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Contains the following MongoDB support tools:
</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/program/mongoldap/#mongodb-binary-bin.mongoldap">
<code class="leafygreen-ui-1l06pbn">
mongoldap
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/install_compass/#std-label-install-compass">
<code class="leafygreen-ui-1l06pbn">
install_compass
</code>
</a>
script
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
mongodecrypt
</code>
binary
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Fundamentals
<a class="headerlink leafygreen-ui-1kepx47" href="#fundamentals" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fundamentals">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
To learn about encryption key management, read
<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>
<p class="leafygreen-ui-1kp3ins">
To learn how Queryable Encryption works and how to use it, read the following sections:
</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/encrypt-and-query/#std-label-qe-fundamentals-encrypt-query">
Encrypted Fields and Enabled Queries
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/qe-create-encryption-schema/#std-label-qe-create-encryption-schema">
Create an Encryption Schema
</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/enable-qe/#std-label-qe-fundamentals-enable-qe">
Enabling Queryable Encryption when Creating Collections
</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/manage-collections/#std-label-qe-fundamentals-collection-management">
Encrypted Collections
</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/manual-encryption/#std-label-qe-fundamentals-manual-encryption">
Explicit Encryption
</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/manage-keys/#std-label-qe-fundamentals-manage-keys">
Rotate and Rewrap Encryption Keys
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/overview-enable-qe/#std-label-qe-overview-enable-qe">
Overview: Enable Queryable Encryption
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/overview-use-qe/#std-label-qe-overview-use-qe">
Overview: Use Queryable Encryption
</a>
</p>
</li>
</ul>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/sharding-high-availability-writes/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Distributed Local Writes for Insert Only Workloads
<a class="headerlink leafygreen-ui-1kepx47" href="#distributed-local-writes-for-insert-only-workloads" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="distributed-local-writes-for-insert-only-workloads">
</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="#scenario" target="_self">
<span>
Scenario
</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">
MongoDB Tag Aware Sharding allows administrators to control data distribution
in a sharded cluster by defining ranges of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
and tagging
them to one or more shards.
</p>
<p class="leafygreen-ui-1kp3ins">
This tutorial uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
Zones
</a>
along with a multi-datacenter
sharded cluster deployment and application-side logic to support distributed
local writes, as well as high write availability in the event of a replica set
election or datacenter failure.
</p>
<p class="leafygreen-ui-1kp3ins">
By defining the zones and the zone ranges
<em>
before
</em>
sharding an empty
or a non-existing collection, the shard collection operation creates
chunks for the defined zone ranges as well as any additional chunks
to cover the entire range of the shard key values and performs an
initial chunk distribution based on the zone ranges. This initial
creation and distribution of chunks allows for faster setup of zoned
sharding. After the initial distribution, the balancer manages the
chunk distribution going forward.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
</a>
for an example.
</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 concepts discussed in this tutorial require a specific deployment
architecture, as well as application-level logic.
</p>
<p class="leafygreen-ui-1kp3ins">
These concepts require familiarity with MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded clusters
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica sets
</a>
, and the general
behavior of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zones
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
This tutorial assumes an insert-only or insert-intensive workload. The
concepts and strategies discussed in this tutorial are not well suited for
use cases that require fast reads or updates.
</p>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Scenario
<a class="headerlink leafygreen-ui-1kepx47" href="#scenario" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="scenario">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Consider an insert-intensive application, where reads are infrequent and low
priority compared to writes. The application writes documents to a sharded
collection, and requires near-constant uptime from the
database to support its SLAs or SLOs.
</p>
<p class="leafygreen-ui-1kp3ins">
The following represents a partial view of the format of documents the
application writes to the database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"56f08c447fe58b2e96f595fa\"),\n \"message_id\" : 329620,\n \"datacenter\" : \"alfa\",\n \"userid\" : 123,\n ...\n}\n{\n \"_id\" : ObjectId(\"56f08c447fe58b2e96f595fb\"),\n \"message_id\" : 578494,\n \"datacenter\" : \"bravo\",\n \"userid\" : 456,\n ...\n}\n{\n \"_id\" : ObjectId(\"56f08c447fe58b2e96f595fc\"),\n \"message_id\" : 689979,\n \"datacenter\" : \"bravo\",\n \"userid\" : 789,\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c447fe58b2e96f595fa"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">329620</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"alfa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</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">}</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c447fe58b2e96f595fb"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">578494</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-number">456</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c447fe58b2e96f595fc"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">689979</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-number">789</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>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-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="shard-key">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The collection uses the
<code class="leafygreen-ui-1l06pbn">
{ datacenter : 1, userid : 1 }
</code>
compound index as
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field in each document allows for creating a tag range on
each distinct datacenter value. Without the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field, it would not
be possible to associate a document with a specific datacenter.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
userid
</code>
field provides a high
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-cardinality">
cardinality
</a>
and low
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-shard-key-frequency">
frequency
</a>
component to the shard key
relative to
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-choose-a-shard-key/#std-label-sharding-shard-key-requirements">
Choosing a Shard Key
</a>
for more
general instructions on selecting a shard key.
</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">
The deployment consists of two datacenters,
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
and
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
. There are
two shards,
<code class="leafygreen-ui-1l06pbn">
shard0000
</code>
and
<code class="leafygreen-ui-1l06pbn">
shard0001
</code>
. Each shard is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
with three members.
<code class="leafygreen-ui-1l06pbn">
shard0000
</code>
has two members on
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
and one
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members">
priority 0 member
</a>
on
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
.
<code class="leafygreen-ui-1l06pbn">
shard0001
</code>
has two members on
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
and one
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-priority-0-member/#std-label-replica-set-secondary-only-members">
priority 0 member
</a>
on
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
.
</p>
<div class="figure css-5vkxs0" style="width:700px">
<img alt="Diagram of sharded cluster architecture for high availability" class="leafygreen-ui-1qnf57e" height="462" src="/docs/manual/images/sharded-cluster-high-availability-architecture.bakedsvg.svg" style="--border-color:#C1C7C6" width="562"/>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-tags">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Tags
<a class="headerlink leafygreen-ui-1kepx47" href="#tags" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="tags">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This application requires one tag per datacenter. Each shard has one
tag assigned to it based on the datacenter containing the majority of
its replica set members. There are two tag ranges, one for each datacenter.
</p>
<dl>
<dt>
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
Datacenter
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Tag shards with a majority of members on this datacenter as
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Create a tag range with:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a lower bound of
<code class="leafygreen-ui-1l06pbn">
{ "datacenter" : "alfa", "userid" : MinKey }
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
an upper bound of
<code class="leafygreen-ui-1l06pbn">
{ "datacenter" : "alfa", "userid" : MaxKey }
</code>
, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the tag
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
</p>
</li>
</ul>
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
Datacenter
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
Tag shards with a majority of members on this datacenter as
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Create a tag range with:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a lower bound of
<code class="leafygreen-ui-1l06pbn">
{ "datacenter" : "bravo", "userid" : MinKey }
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
an upper bound of
<code class="leafygreen-ui-1l06pbn">
{ "datacenter" : "bravo", "userid" : MaxKey }
</code>
, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the tag
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
</p>
</li>
</ul>
</dd>
</dl>
<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/mongodb-extended-json/#mongodb-bsontype-MinKey">
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey">
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
</a>
values are reserved special
values for comparisons
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Based on the
configured tags and tag ranges,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
routes documents with
<code class="leafygreen-ui-1l06pbn">
datacenter : alfa
</code>
to the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
datacenter, and documents with
<code class="leafygreen-ui-1l06pbn">
datacenter : bravo
</code>
to the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
datacenter.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Write Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#write-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="write-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If an inserted or updated document matches a configured tag range, it can only
be written to a shard with the related tag.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB can write documents that do not match a configured tag range to any
shard in the cluster.
</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 behavior described above requires the cluster to be in a steady state
with no chunks violating a configured tag range. See the following section
on the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-writes-balancing" target="_self">
<span>
balancer
</span>
</a>
for
more information.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-writes-balancing">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Balancer
<a class="headerlink leafygreen-ui-1kepx47" href="#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="balancer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration">
migrates
</a>
the tagged chunks to the appropriate shard. Until
the migration, shards may contain chunks that violate configured tag ranges
and tags. Once balancing completes, shards should only contain chunks whose
ranges do not violate its assigned tags and tag ranges.
</p>
<p class="leafygreen-ui-1kp3ins">
Adding or removing tags or tag ranges can result in chunk migrations.
Depending on the size of your data set and the number of chunks a tag range
affects, these migrations may impact cluster performance. Consider running
your
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
during specific scheduled windows.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-schedule-balancing-window">
Schedule the Balancing Window
</a>
for a tutorial on how to set a
scheduling window.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-application-behavior">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Application Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#application-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="application-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, the application writes to the nearest datacenter. If the local
datacenter is down, or if writes to that datacenter are not acknowledged
within a set time period, the application switches to the other available
datacenter by changing the value of the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field before attempting
to write the document to the database.
</p>
<p class="leafygreen-ui-1kp3ins">
The application supports write timeouts. The application uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write Concern
</a>
to set a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-wtimeout">
timeout
</a>
for each write
operation.
</p>
<p class="leafygreen-ui-1kp3ins">
If the application encounters a write or timeout error, it modifies the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field in each document and performs the write. This routes the
document to the other datacenter. If both datacenters are down, then writes
cannot succeed. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-write-failure" target="_self">
<span>
Resolve Write Failure
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The application periodically checks connectivity to any data
centers marked as "down". If connectivity is restored, the application can
continue performing normal write operations.
</p>
<p class="leafygreen-ui-1kp3ins">
Given the switching logic, as well as any load balancers or similar mechanisms
in place to handle client traffic between datacenters, the application cannot
predict which of the two datacenters a given document was written to. To
ensure that no documents are missed as a part of read operations, the
application
<em>
must
</em>
perform
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-broadcast">
broadcast queries
</a>
by
<em>
not
</em>
including the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field as a
part of any query.
</p>
<p class="leafygreen-ui-1kp3ins">
The application performs reads using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
read preference
</a>
of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-nearest">
<code class="leafygreen-ui-1l06pbn">
nearest
</code>
</a>
to reduce latency.
</p>
<p class="leafygreen-ui-1kp3ins">
It is possible for a write operation to succeed despite a reported timeout
error. The application responds to the error by attempting to re-write
the document to the other datacenter - this can result in a document being
duplicated across both datacenters. The application resolves duplicates
as a part of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-writes-read-resolution" target="_self">
<span>
read
</span>
</a>
logic.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Switching Logic
<a class="headerlink leafygreen-ui-1kepx47" href="#switching-logic" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="switching-logic">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The application has logic to switch datacenters if one or more writes fail, or
if writes are not
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
acknowledged
</a>
within a set time
period. The application modifies the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field based on the target
datacenter's
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-tags" target="_self">
<span>
tag
</span>
</a>
to direct the
document towards that datacenter.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, an application attempting to write to the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
datacenter
might follow this general procedure:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Attempt to write document, specifying
<code class="leafygreen-ui-1l06pbn">
datacenter : alfa
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
On write timeout or error, log
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
as momentarily down.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Attempt to write same document, modifying
<code class="leafygreen-ui-1l06pbn">
datacenter : bravo
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
On write timeout or error, log
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
as momentarily down.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If both
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
and
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
are down, log and report errors.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-write-failure" target="_self">
<span>
Resolve Write Failure
<!-- -->
.
</span>
</a>
</p>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-write-configure-tags">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Configure Shard Tags
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-shard-tags" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-shard-tags">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You must be connected 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>
associated with the target
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
in order to proceed. You cannot create tags by
connecting directly to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
replica set member.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Tag each shard.Tag each shard in the alfa data center with the alfa tag.Tag each shard in the bravo data center with the bravo tag.You can review the tags assigned to any given shard by running\nsh.status()."},{"@type":"HowToStep","text":"Define ranges for each tag.Define the range for the alfa database and associate it to the alfa\ntag using the sh.addTagRange() method. This method requires:The full namespace of the target collection.The inclusive lower bound of the range.The exclusive upper bound of the range.The name of the tag.Define the range for the bravo database and associate it to the\nbravo tag using the sh.addTagRange() method. This method\nrequires:The full namespace of the target collection.The inclusive lower bound of the range.The exclusive upper bound of the range.The name of the tag.The MinKey and MaxKey values are reserved special\nvalues for comparisons. MinKey always compares as less than\nevery other possible value, while MaxKey always compares as\ngreater than every other possible value. The configured ranges capture every\nuser for each datacenter."},{"@type":"HowToStep","text":"Review the changes.The next time the balancer runs, it\nmigrates data across the shards\nrespecting the configured zones.Once balancing finishes, the shards tagged as alfa should only\ncontain documents with datacenter : alfa, while shards tagged as\nbravo should only contain documents with datacenter : bravo.You can review the chunk distribution by running sh.status()."}],"name":"Configure Shard Tags","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">
Tag each shard.
<a class="headerlink leafygreen-ui-1kepx47" href="#tag-each-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="tag-each-shard">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Tag each shard in the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
data center with the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
tag.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardTag(\"shard0000\", \"alfa\")\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">sh.<span class="lg-highlight-title lg-highlight-function">addShardTag</span>(<span class="lg-highlight-string">"shard0000"</span>, <span class="lg-highlight-string">"alfa"</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">
Tag each shard in the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
data center with the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
tag.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardTag(\"shard0001\", \"bravo\")\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">sh.<span class="lg-highlight-title lg-highlight-function">addShardTag</span>(<span class="lg-highlight-string">"shard0001"</span>, <span class="lg-highlight-string">"bravo"</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 review the tags assigned to any given shard by running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
<code class="leafygreen-ui-1l06pbn">
sh.status()
</code>
.
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Define ranges for each tag.
<a class="headerlink leafygreen-ui-1kepx47" href="#define-ranges-for-each-tag" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="define-ranges-for-each-tag">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Define the range for the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
database and associate it to the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
tag using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange">
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</a>
method. This method requires:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The full namespace of the target collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The inclusive lower bound of the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The exclusive upper bound of the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The name of the tag.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addTagRange( \n \"<database>.<collection>\",\n { \"datacenter\" : \"alfa\", \"userid\" : MinKey },\n { \"datacenter\" : \"alfa\", \"userid\" : MaxKey }, \n \"alfa\"\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">sh.<span class="lg-highlight-title lg-highlight-function">addTagRange</span>( </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<database>.<collection>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"alfa"</span>, <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"alfa"</span>, <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span> }<!-- -->, </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"alfa"</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">
Define the range for the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
database and associate it to the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
tag using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange">
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</a>
method. This method
requires:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The full namespace of the target collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The inclusive lower bound of the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The exclusive upper bound of the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The name of the tag.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addTagRange( \n \"<database>.<collection>\",\n { \"datacenter\" : \"bravo\", \"userid\" : MinKey },\n { \"datacenter\" : \"bravo\", \"userid\" : MaxKey }, \n \"bravo\"\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">sh.<span class="lg-highlight-title lg-highlight-function">addTagRange</span>( </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<database>.<collection>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>, <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>, <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span> }<!-- -->, </td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bravo"</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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey">
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey">
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
</a>
values are reserved special
values for comparisons.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MinKey">
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
</a>
always compares as less than
every other possible value, while
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#mongodb-bsontype-MaxKey">
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
</a>
always compares as
greater than every other possible value. The configured ranges capture every
user for each
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
.
</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">
Review the changes.
<a class="headerlink leafygreen-ui-1kepx47" href="#review-the-changes" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="review-the-changes">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The next time the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
runs, it
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration">
migrates
</a>
data across the shards
respecting the configured zones.
</p>
<p class="leafygreen-ui-1kp3ins">
Once balancing finishes, the shards tagged as
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
should only
contain documents with
<code class="leafygreen-ui-1l06pbn">
datacenter : alfa
</code>
, while shards tagged as
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
should only contain documents with
<code class="leafygreen-ui-1l06pbn">
datacenter : bravo
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You can review the chunk distribution by running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
<code class="leafygreen-ui-1l06pbn">
sh.status()
</code>
.
</a>
</p>
</section>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-write-failure">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Resolve Write Failure
<a class="headerlink leafygreen-ui-1kepx47" href="#resolve-write-failure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="resolve-write-failure">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When the application's default datacenter is down or inaccessible, the
application changes the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field to the other
datacenter.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the application attempts to write the following document to the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
datacenter by default:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"56f08c447fe58b2e96f595fa\"),\n \"message_id\" : 329620,\n \"datacenter\" : \"alfa\",\n \"userid\" : 123,\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c447fe58b2e96f595fa"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">329620</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"alfa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</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">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 application receives an error on attempted write, or if the write
acknowledgment takes too long, the application logs the datacenter as
unavailable and alters the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field to point to the
<code class="leafygreen-ui-1l06pbn">
bravo
</code>
datacenter.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"56f08c457fe58b2e96f595fb\"),\n \"message_id\" : 329620,\n \"datacenter\" : \"bravo\",\n \"userid\" : 123,\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c457fe58b2e96f595fb"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">329620</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</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">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 periodically checks the
<code class="leafygreen-ui-1l06pbn">
alfa
</code>
datacenter for
connectivity. If the datacenter is reachable again, the application can resume
normal writes.
</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 possible that the original write to
<code class="leafygreen-ui-1l06pbn">
datacenter : alfa
</code>
succeeded,
especially if the error was related to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-wtimeout">
timeout
</a>
.
If so, the document with
<code class="leafygreen-ui-1l06pbn">
message_id : 329620
</code>
may now be duplicated
across both datacenters. Applications must resolve duplicates as a part
of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-high-availability-writes-read-resolution" target="_self">
<span>
read operations
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-high-availability-writes-read-resolution">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Resolve Duplicate Documents on Reads
<a class="headerlink leafygreen-ui-1kepx47" href="#resolve-duplicate-documents-on-reads" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="resolve-duplicate-documents-on-reads">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The application's switching logic allows for potential document duplication.
When performing reads, the application resolves any duplicate documents on the
application layer.
</p>
<p class="leafygreen-ui-1kp3ins">
The following query searches for documents where the
<code class="leafygreen-ui-1l06pbn">
userid
</code>
is
<code class="leafygreen-ui-1l06pbn">
123
</code>
.
Note that while
<code class="leafygreen-ui-1l06pbn">
userid
</code>
is part of the shard key, the query does not
include the
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
field, and therefore does not perform a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-query-router/#std-label-sharding-mongos-targeted">
targeted read operation
<!-- -->
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find( { \"userid\" : 123 } )","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-string">"userid"</span> <!-- -->: <span class="lg-highlight-number">123</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 results show that the document with
<code class="leafygreen-ui-1l06pbn">
message_id
</code>
of
<code class="leafygreen-ui-1l06pbn">
329620
</code>
has been
inserted into MongoDB twice, probably as a result of a delayed write
acknowledgment.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"56f08c447fe58b2e96f595fa\"),\n \"message_id\" : 329620\n \"datacenter\" : \"alfa\",\n \"userid\" : 123,\n data : {...}\n}\n{\n \"_id\" : ObjectId(\"56f08c457fe58b2e96f595fb\"),\n \"message_id\" : 329620\n \"datacenter\" : \"bravo\",\n \"userid\" : 123,\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c447fe58b2e96f595fa"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">329620</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"alfa"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</span> <!-- -->: <span class="lg-highlight-number">123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->data <!-- -->: <!-- -->{<!-- -->...<!-- -->}</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"56f08c457fe58b2e96f595fb"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"message_id"</span> <!-- -->: <span class="lg-highlight-number">329620</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"datacenter"</span> <!-- -->: <span class="lg-highlight-string">"bravo"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"userid"</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">}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 can either ignore the duplicates, taking one of the two
documents, or it can attempt to trim the duplicates until only a single
document remains.
</p>
<p class="leafygreen-ui-1kp3ins">
One method for trimming duplicates is to use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.getTimestamp/#mongodb-method-ObjectId.getTimestamp">
<code class="leafygreen-ui-1l06pbn">
ObjectId.getTimestamp()
</code>
</a>
method to extract the timestamp from the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field. The application can then keep either the first document
inserted, or the last document inserted. This assumes the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field uses the MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId/#mongodb-method-ObjectId">
<code class="leafygreen-ui-1l06pbn">
ObjectId()
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For example, using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.getTimestamp/#mongodb-method-ObjectId.getTimestamp">
<code class="leafygreen-ui-1l06pbn">
getTimestamp()
</code>
</a>
on the document
with
<code class="leafygreen-ui-1l06pbn">
ObjectId("56f08c447fe58b2e96f595fa")
</code>
returns:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ISODate(\"2016-03-22T00:05:24Z\")","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">ISODate</span>(<span class="lg-highlight-string">"2016-03-22T00:05:24Z"</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">
Using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId.getTimestamp/#mongodb-method-ObjectId.getTimestamp">
<code class="leafygreen-ui-1l06pbn">
getTimestamp()
</code>
</a>
on the document with
<code class="leafygreen-ui-1l06pbn">
ObjectId("56f08c457fe58b2e96f595fb")
</code>
returns:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"ISODate(\"2016-03-22T00:05:25Z\")","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">ISODate</span>(<span class="lg-highlight-string">"2016-03-22T00:05:25Z"</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/dateAdd/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$dateAdd (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-dateadd--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="-dateadd--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">
$dateAdd
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-dateAdd" 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.-dateAdd">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Increments a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Date/#mongodb-method-Date">
<code class="leafygreen-ui-1l06pbn">
Date()
</code>
</a>
object by a
specified number of time units.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dateAdd" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</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":"{\n $dateAdd: {\n startDate: <expression>,\n unit: <expression>,\n amount: <expression>,\n timezone: <tzexpression>\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">$dateAdd</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <<span class="lg-highlight-title lg-highlight-class">Expression</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <<span class="lg-highlight-title lg-highlight-class">Expression</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <<span class="lg-highlight-title lg-highlight-class">Expression</span>><!-- -->,</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"> <!-- -->}</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">
Returns a
<code class="leafygreen-ui-1l06pbn">
Date()
</code>
. The
<code class="leafygreen-ui-1l06pbn">
startDate
</code>
can be any expression that
resolves to type Date, Timestamp or ObjectId. No matter which data
type is used as input, the value returned will be a
<code class="leafygreen-ui-1l06pbn">
Date()
</code>
object.
</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>
Required/Optional
</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">
startDate
</code>
</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>
The beginning date, in UTC, for the addition operation. The
<code class="leafygreen-ui-1l06pbn">
startDate
</code>
can be any
<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">
unit
</code>
</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>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
unit
</code>
used to measure the
<code class="leafygreen-ui-1l06pbn">
amount
</code>
of time added to
the
<code class="leafygreen-ui-1l06pbn">
startDate
</code>
. The
<code class="leafygreen-ui-1l06pbn">
unit
</code>
is an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to
one of the following strings:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
year
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
quarter
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
week
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
month
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
day
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
hour
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
minute
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
second
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
millisecond
</code>
</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">
amount
</code>
</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>
The number of
<code class="leafygreen-ui-1l06pbn">
units
</code>
added to the
<code class="leafygreen-ui-1l06pbn">
startDate
</code>
. The
<code class="leafygreen-ui-1l06pbn">
amount
</code>
is an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
expression
</a>
that resolves to an integer or long. The
<code class="leafygreen-ui-1l06pbn">
amount
</code>
can also
resolve to an integral decimal or a double if that value can
be converted to a long without loss of precision.
</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>
Optional
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The timezone to carry out the operation.
<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 displayed in
<code class="leafygreen-ui-1l06pbn">
UTC
</code>
.
</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>
Olson Timezone Identifier
</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\"","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-string">"America/New_York"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"Europe/London"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-string">"GMT"</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>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
UTC Offset
</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\"","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">+<!-- -->/-<!-- -->[hh]:[mm], e.g. <span class="lg-highlight-string">"+04:45"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">+<!-- -->/-<!-- -->[hh][mm], e.g. <span class="lg-highlight-string">"-0530"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">+<!-- -->/-<!-- -->[hh], e.g. <span class="lg-highlight-string">"+03"</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>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information on expressions and types see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
Expression Operators
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-bson-types">
BSON Types
<!-- -->
.
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Time Measurement
<a class="headerlink leafygreen-ui-1kepx47" href="#time-measurement" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-measurement">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB follows prevaling database usage and works with time in UTC. The
<code class="leafygreen-ui-1l06pbn">
dateAdd
</code>
expression always takes a
<code class="leafygreen-ui-1l06pbn">
startDate
</code>
in UTC and returns
a result in UTC. If the
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
is specified, the calculation will
be done using the specified
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
. The timezone is especially
important when a calculation involves Daylight Savings Time (DST).
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
unit
</code>
is a
<code class="leafygreen-ui-1l06pbn">
month
</code>
, or larger the operation adjusts to
account for the last day of the month. Adding one
<code class="leafygreen-ui-1l06pbn">
month
</code>
on the last
day of October, for example, demonstrates the "last-day-of-the-month"
adjustment.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $dateAdd:\n {\n startDate: ISODate(\"2020-10-31T12:10:05Z\"),\n unit: \"month\",\n 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">{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-10-31T12:10:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"month"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <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">
Notice that the date returned,
<code class="leafygreen-ui-1l06pbn">
ISODate("2020-11-30T12:10:05Z")
</code>
, is
the 30th and not the 31st since November has fewer days than October.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Time Zone
<a class="headerlink leafygreen-ui-1kepx47" href="#time-zone" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-zone">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When using an Olson Timezone Identifier in the
<code class="leafygreen-ui-1l06pbn">
<timezone>
</code>
field, MongoDB applies the
<span class="leafygreen-ui-vm4wms" tabindex="0">
DST
</span>
offset
if applicable for the specified timezone.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, consider a
<code class="leafygreen-ui-1l06pbn">
sales
</code>
collection with the following document:
</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\" : 20,\n \"quantity\" : 5,\n \"date\" : ISODate(\"2017-05-20T10:24:51.303Z\")\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">20</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">5</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">"2017-05-20T10:24:51.303Z"</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 illustrates how MongoDB handles the DST
offset for the Olson Timezone Identifier. The example uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/hour/#mongodb-expression-exp.-hour">
<code class="leafygreen-ui-1l06pbn">
$hour
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/minute/#mongodb-expression-exp.-minute">
<code class="leafygreen-ui-1l06pbn">
$minute
</code>
</a>
operators to return the
corresponding portions of 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 $project: {\n \"nycHour\": {\n $hour: { date: \"$date\", timezone: \"-05:00\" }\n },\n \"nycMinute\": {\n $minute: { date: \"$date\", timezone: \"-05:00\" }\n },\n \"gmtHour\": {\n $hour: { date: \"$date\", timezone: \"GMT\" }\n },\n \"gmtMinute\": {\n $minute: { date: \"$date\", timezone: \"GMT\" } },\n \"nycOlsonHour\": {\n $hour: { date: \"$date\", timezone: \"America/New_York\" }\n },\n \"nycOlsonMinute\": {\n $minute: { date: \"$date\", timezone: \"America/New_York\" }\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">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"> <span class="lg-highlight-attr">$project</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-05:00"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"-05:00"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"gmtHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"GMT"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"gmtMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</span>, <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"GMT"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycOlsonHour"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$hour</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</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"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycOlsonMinute"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$minute</span>: <!-- -->{ <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$date"</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"> }</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 \"nycHour\" : 5,\n \"nycMinute\" : 24,\n \"gmtHour\" : 10,\n \"gmtMinute\" : 24,\n \"nycOlsonHour\" : 6,\n \"nycOlsonMinute\" : 24\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">"nycHour"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycMinute"</span> <!-- -->: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"gmtHour"</span> <!-- -->: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"gmtMinute"</span> <!-- -->: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycOlsonHour"</span> <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"nycOlsonMinute"</span> <!-- -->: <span class="lg-highlight-number">24</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>
<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">
Add a Future Date
<a class="headerlink leafygreen-ui-1kepx47" href="#add-a-future-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="add-a-future-date">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Consider a collection of customer orders with these documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.insertMany(\n [\n { custId: 456, purchaseDate: ISODate(\"2020-12-31\") },\n { custId: 457, purchaseDate: ISODate(\"2021-02-28\") },\n { custId: 458, purchaseDate: ISODate(\"2021-02-26\") }\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">shipping</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">custId</span>: <span class="lg-highlight-number">456</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-12-31"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">457</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-28"</span>) }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">458</span>, <span class="lg-highlight-attr">purchaseDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-26"</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 normal shipping time is 3 days. You can use
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
in an
aggregation pipeline to set an
<code class="leafygreen-ui-1l06pbn">
expectedDeliveryDate
</code>
3 days in the
future.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.aggregate(\n [\n {\n $project:\n {\n expectedDeliveryDate:\n {\n $dateAdd:\n {\n startDate: \"$purchaseDate\",\n unit: \"day\",\n amount: 3\n }\n }\n }\n },\n {\n $merge: \"shipping\"\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">shipping</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">expectedDeliveryDate</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">$dateAdd</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"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$purchaseDate"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">3</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"> }</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">$merge</span>: <span class="lg-highlight-string">"shipping"</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">
After adding 3 days to the
<code class="leafygreen-ui-1l06pbn">
purchaseDate
</code>
with
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
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
<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 updates the
original documents with the
<code class="leafygreen-ui-1l06pbn">
expectedDeliveryDate
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The resulting 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\" : ObjectId(\"603dd4b2044b995ad331c0b2\"),\n \"custId\" : 456,\n \"purchaseDate\" : ISODate(\"2020-12-31T00:00:00Z\"),\n \"expectedDeliveryDate\" : ISODate(\"2021-01-03T00:00:00Z\")\n}\n{\n \"_id\" : ObjectId(\"603dd4b2044b995ad331c0b3\"),\n \"custId\" : 457,\n \"purchaseDate\" : ISODate(\"2021-02-28T00:00:00Z\"),\n \"expectedDeliveryDate\" : ISODate(\"2021-03-03T00:00:00Z\")\n}\n{\n \"_id\" : ObjectId(\"603dd4b2044b995ad331c0b4\"),\n \"custId\" : 458,\n \"purchaseDate\" : ISODate(\"2021-02-26T00:00:00Z\"),\n \"expectedDeliveryDate\" : ISODate(\"2021-03-01T00:00:00Z\")\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">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b2"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">456</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-12-31T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-01-03T00:00:00Z"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">457</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-28T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-03T00:00:00Z"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"603dd4b2044b995ad331c0b4"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">458</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"purchaseDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-02-26T00:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"expectedDeliveryDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-01T00:00:00Z"</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">
Filter on a Date Range
<a class="headerlink leafygreen-ui-1kepx47" href="#filter-on-a-date-range" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="filter-on-a-date-range">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Update the
<code class="leafygreen-ui-1l06pbn">
shipping
</code>
collection from the last example with this code
to add delivery dates to the documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.updateOne(\n { custId: 456 },\n { $set: { deliveryDate: ISODate( \"2021-01-10\" ) } }\n)\n\ndb.shipping.updateOne(\n { custId: 457 },\n { $set: { deliveryDate: ISODate( \"2021-03-01\" ) } }\n)\n\ndb.shipping.updateOne(\n { custId: 458 },\n { $set: { deliveryDate: ISODate( \"2021-03-02\" ) } }\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">shipping</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">custId</span>: <span class="lg-highlight-number">456</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-01-10"</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">shipping</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">custId</span>: <span class="lg-highlight-number">457</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-01"</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">shipping</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">custId</span>: <span class="lg-highlight-number">458</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">deliveryDate</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-03-02"</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 want to find late shipments. Use
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
in a
<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 to create a filter that matches documents in a
range of dates defined by a starting point (
<code class="leafygreen-ui-1l06pbn">
$purchaseDate
</code>
) and a
time period given by
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.shipping.aggregate(\n [\n {\n $match:\n {\n $expr:\n {\n $gt:\n [ \"$deliveryDate\",\n {\n $dateAdd:\n {\n startDate: \"$purchaseDate\",\n unit: \"day\",\n amount: 5\n }\n }\n ]\n }\n }\n },\n {\n $project:\n {\n _id: 0,\n custId: 1,\n purchased:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d\",\n date: \"$purchaseDate\"\n }\n },\n delivery:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d\",\n date: \"$deliveryDate\"\n }\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-7razhx">db.<span class="lg-highlight-property">shipping</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">$match</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$gt</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <span class="lg-highlight-string">"$deliveryDate"</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">$dateAdd</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"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$purchaseDate"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">5</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"> ]</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">$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">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">custId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">purchased</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$purchaseDate"</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">delivery</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$deliveryDate"</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/match/#mongodb-pipeline-pipe.-match">
<code class="leafygreen-ui-1l06pbn">
$match
</code>
</a>
stage uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/gt/#mongodb-expression-exp.-gt">
<code class="leafygreen-ui-1l06pbn">
$gt
</code>
</a>
and
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
in
an expression (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
) to compare the actual
<code class="leafygreen-ui-1l06pbn">
deliveryDate
</code>
with an expected date. Documents with delivery dates more than 5 days
after the
<code class="leafygreen-ui-1l06pbn">
purchaseDate
</code>
are passed on to 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.
</p>
<p class="leafygreen-ui-1kp3ins">
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 uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString">
<code class="leafygreen-ui-1l06pbn">
$dateToString
</code>
</a>
expression to convert the dates to a more readable format. Without the
conversion, MongoDB returns the date in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-ISODate">
ISODate
</a>
format and
assumes a UTC timezone.
</p>
<p class="leafygreen-ui-1kp3ins">
In this example only one record is returned:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"custId\" : 456, \"purchased\" : \"2020-12-31\", \"delivery\" : \"2021-01-10\" }","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-string">"custId"</span> <!-- -->: <span class="lg-highlight-number">456</span>, <span class="lg-highlight-string">"purchased"</span> <!-- -->: <span class="lg-highlight-string">"2020-12-31"</span>, <span class="lg-highlight-string">"delivery"</span> <!-- -->: <span class="lg-highlight-string">"2021-01-10"</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Adjust for Daylight Savings Time
<a class="headerlink leafygreen-ui-1kepx47" href="#adjust-for-daylight-savings-time" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="adjust-for-daylight-savings-time">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
All dates are stored internally in UTC time. When a
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
is
specified,
<code class="leafygreen-ui-1l06pbn">
$dateAdd
</code>
uses local time to carry out the calculations.
The results are displayed in UTC.
</p>
<p class="leafygreen-ui-1kp3ins">
You have customers in several timezones and you want to see what effect
daylight savings time might have on your billing periods if you bill by
<code class="leafygreen-ui-1l06pbn">
day
</code>
or by
<code class="leafygreen-ui-1l06pbn">
hour
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Create this collection of connection times:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.billing.insertMany(\n [\n {\n location: \"America/New_York\",\n login: ISODate(\"2021-03-13T10:00:00-0500\"),\n logout: ISODate(\"2021-03-14T18:00:00-0500\")\n },\n {\n location: \"America/Mexico_City\",\n login: ISODate(\"2021-03-13T10:00:00-00:00\"),\n logout: ISODate(\"2021-03-14T08:00:00-0500\")\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">billing</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-attr">location</span>: <span class="lg-highlight-string">"America/New_York"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">login</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-13T10:00:00-0500"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logout</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-14T18:00:00-0500"</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">location</span>: <span class="lg-highlight-string">"America/Mexico_City"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">login</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-13T10:00:00-00:00"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">logout</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-14T08:00:00-0500"</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">
First add 1 day, then add 24 hours to the
<code class="leafygreen-ui-1l06pbn">
login
</code>
dates in each
document.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.billing.aggregate(\n [\n {\n $project:\n {\n _id: 0,\n location: 1,\n start:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date: \"$login\"\n }\n },\n days:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date:\n {\n $dateAdd:\n {\n startDate: \"$login\",\n unit: \"day\",\n amount: 1,\n timezone: \"$location\"\n }\n }\n }\n },\n hours:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date:\n {\n $dateAdd:\n {\n startDate: \"$login\",\n unit: \"hour\",\n amount: 24,\n timezone: \"$location\"\n }\n }\n }\n },\n startTZInfo:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date: \"$login\",\n timezone: \"$location\"\n }\n },\n daysTZInfo:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date:\n {\n $dateAdd:\n {\n startDate: \"$login\",\n unit: \"day\",\n amount: 1,\n timezone: \"$location\"\n }\n },\n timezone: \"$location\"\n }\n },\n hoursTZInfo:\n {\n $dateToString:\n {\n format: \"%Y-%m-%d %H:%M\",\n date:\n {\n $dateAdd:\n {\n startDate: \"$login\",\n unit: \"hour\",\n amount: 24,\n timezone: \"$location\"\n }\n },\n timezone: \"$location\"\n }\n },\n }\n }\n ]\n).pretty()","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">billing</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">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">start</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$login"</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">days</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</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">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">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"hour"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</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">startTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">date</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</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">daysTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"day"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</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">timezone</span>: <span class="lg-highlight-string">"$location"</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">hoursTZInfo</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateToString</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">format</span>: <span class="lg-highlight-string">"%Y-%m-%d %H:%M"</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"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$dateAdd</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">startDate</span>: <span class="lg-highlight-string">"$login"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"hour"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">amount</span>: <span class="lg-highlight-number">24</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timezone</span>: <span class="lg-highlight-string">"$location"</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">timezone</span>: <span class="lg-highlight-string">"$location"</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-title lg-highlight-function">pretty</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/operator/aggregation/dateToString/#mongodb-expression-exp.-dateToString">
<code class="leafygreen-ui-1l06pbn">
$dateToString
</code>
</a>
expression reformats the output for
readability. Results are summarized here:
</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>
New York
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Mexico City
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Start
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-13 15:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-13 10:00
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Start, TZ Info
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-13 10:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-13 04:00
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1 Day
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 14:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 10:00
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
1 Day, TZ Info
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 10:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 04:00
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
24 Hours
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 15:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 10:00
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
24 Hours, TZ Info
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 11:00
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2021-03-14 04:00
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The chart highlights several points:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Unformatted dates are returned in UTC. The
<code class="leafygreen-ui-1l06pbn">
$login
</code>
for New York is
UTC -5, however the
<code class="leafygreen-ui-1l06pbn">
start
</code>
,
<code class="leafygreen-ui-1l06pbn">
days
</code>
, and
<code class="leafygreen-ui-1l06pbn">
hours
</code>
rows display
the time in UTC.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
March 14th is the start of DST in New York, but not in Mexico. The
calculated time is adjusted when a location switches to DST and
crosses from one
<code class="leafygreen-ui-1l06pbn">
day
</code>
to the next.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
DST modifies the length of the
<code class="leafygreen-ui-1l06pbn">
day
</code>
, not the
<code class="leafygreen-ui-1l06pbn">
hour
</code>
. There is no
DST change for
<code class="leafygreen-ui-1l06pbn">
hours
</code>
. There is an only an adjustment for DST when
the measurement
<code class="leafygreen-ui-1l06pbn">
unit
</code>
is
<code class="leafygreen-ui-1l06pbn">
day
</code>
or larger and the computation
crosses a clock change in the specified
<code class="leafygreen-ui-1l06pbn">
timezone
</code>
.
</p>
</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/reference/operator/aggregation/dateSubtract/#mongodb-expression-exp.-dateSubtract">
<code class="leafygreen-ui-1l06pbn">
$dateSubtract
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/dateDiff/#mongodb-expression-exp.-dateDiff">
<code class="leafygreen-ui-1l06pbn">
$dateDiff
</code>
</a>
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/release-notes/7.0-downgrade/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Downgrade
<!-- -->
7.0
<!-- -->
to
<!-- -->
6.0
<a class="headerlink leafygreen-ui-1kepx47" href="#downgrade-newversion-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-to-oldversion">
</div>
</a>
</h1>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, binary downgrades are no longer supported for
MongoDB Community Edition.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 7.0, you cannot downgrade your Enterprise deployment's
binary version without assistance from support.
</p>
<p class="leafygreen-ui-1kp3ins">
To downgrade from
<!-- -->
7.0
<!-- -->
to
<!-- -->
6.0
<!-- -->
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://support.mongodb.com/" target="_self">
<span>
submit a support request
</span>
</a>
or contact your technical support
representative.
</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
<!-- -->
7.0-series
<!-- -->
to a
<!-- -->
6.0-series
<!-- -->
deployment.
However, further downgrading that
<!-- -->
6.0-series
<!-- -->
deployment to a
<!-- -->
5.0-series
<!-- -->
deployment is not supported.
</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/release-notes/7.0/#std-label-7.0-downgrade-considerations">
Downgrade Considerations
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/cursor.allowDiskUse/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
cursor.allowDiskUse()
<a class="headerlink leafygreen-ui-1kepx47" href="#cursor.allowdiskuse--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.allowdiskuse--">
</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="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
cursor.allowDiskUse()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-cursor.allowDiskUse" 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.allowDiskUse">
</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">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
allowDiskUse()
</code>
</span>
</a>
to either allow or prohibit
writing temporary files on disk when a pipeline stage exceeds
the 100 megabyte limit. Starting in MongoDB 6.0, operations that
require greater than 100 megabytes of memory automatically write
data to temporary files by default.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
allowDiskUse()
</code>
</span>
</a>
has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.find(<match>).sort(<sort>).allowDiskUse()","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>(<<!-- -->match<!-- -->><!-- -->).<span class="lg-highlight-title lg-highlight-function">sort</span>(<<!-- -->sort<!-- -->><!-- -->).<span class="lg-highlight-title lg-highlight-function">allowDiskUse</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>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#std-label-sort-index-use">
Sort and Index Use
</a>
for more information on blocking sort
operations.
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Interaction with
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#interaction-with-allowdiskusebydefault" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-allowdiskusebydefault">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, pipeline stages that require more than 100
megabytes of memory to execute write temporary files to disk by
default.
</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">
Prior to MongoDB 6.0,
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(false)
</code>
and
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(true)
</code>
have the same effect. In MongoDB 6.0, both
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
and the legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell behave the following way:
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.allowDiskUseByDefault">
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
</a>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
(this is the default):
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse()
</code>
has no additional effect
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(true)
</code>
has no additional effect
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(false)
</code>
prohibits the query from writing temporary
files to disk
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.allowDiskUseByDefault">
<code class="leafygreen-ui-1l06pbn">
allowDiskUseByDefault
</code>
</a>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse()
</code>
enables writing temporary files to disk
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(true)
</code>
enables writing temporary files to disk
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
.allowDiskUse(false)
</code>
has no additional effect
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Supports Large Non-Indexed Sorts Only
<a class="headerlink leafygreen-ui-1kepx47" href="#supports-large-non-indexed-sorts-only" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="supports-large-non-indexed-sorts-only">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
cursor.allowDiskUse()
</code>
</span>
</a>
has no effect on sort operations
answered using an index
<em>
or
</em>
non-indexed ("blocking") sort operations
which require less than 100 megabytes of memory. For more complete
documentation on blocking sorts and sort index use, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#std-label-sort-index-use">
Sort and Index Use
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To check if MongoDB must perform an blocking sort, append
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.explain/#mongodb-method-cursor.explain">
<code class="leafygreen-ui-1l06pbn">
cursor.explain()
</code>
</a>
to the query and check the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/explain-results/#std-label-explain-results">
explain results
</a>
. If the query plan
contains a
<code class="leafygreen-ui-1l06pbn">
SORT
</code>
stage, then MongoDB must perform an
blocking sort operation subject to the 100 megabyte memory limit.
</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">
Consider a collection
<code class="leafygreen-ui-1l06pbn">
sensors
</code>
with only the default index on
<code class="leafygreen-ui-1l06pbn">
_id
</code>
. The collection contains documents similar to the
following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"sensor-name\" : \"TEMP-21425\",\n \"sensor-location\" : \"Unit 12\",\n \"reading\" : {\n \"timestamp\" : Timestamp(1580247215, 1),\n \"value\" : 212,\n \"unit\" : \"Fahrenheit\"\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">"sensor-name"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"TEMP-21425"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"sensor-location"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Unit 12"</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"reading"</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">"timestamp"</span> <span class="lg-highlight-punctuation">:</span> Timestamp(<span class="lg-highlight-number">1580247215</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">"value"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-number">212</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">"unit"</span> <span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-string">"Fahrenheit"</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>
<p class="leafygreen-ui-1kp3ins">
The following operation includes a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#mongodb-method-cursor.sort">
<code class="leafygreen-ui-1l06pbn">
cursor.sort()
</code>
</a>
on the
field
<code class="leafygreen-ui-1l06pbn">
reading.timestamp
</code>
. The operation also includes
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
cursor.allowDiskUse()
</code>
</span>
</a>
to support the sort operation.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sensors.find({\"sensor-location\" : \"Unit 12\"}).\n sort({\"reading.timestamp\" : 1}).\n allowDiskUse()","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">sensors</span>.<span class="lg-highlight-title lg-highlight-function">find</span>(<!-- -->{<span class="lg-highlight-string">"sensor-location"</span> <!-- -->: <span class="lg-highlight-string">"Unit 12"</span>}).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">sort</span>(<!-- -->{<span class="lg-highlight-string">"reading.timestamp"</span> <!-- -->: <span class="lg-highlight-number">1</span>}).</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">allowDiskUse</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">
Since
<code class="leafygreen-ui-1l06pbn">
reading.timestamp
</code>
is not included in an index, MongoDB
must perform a blocking sort operation to return results in the
requested sort order. By specifying
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
allowDiskUse()
</code>
</span>
</a>
,
MongoDB can process the sort operation
<em>
even if
</em>
it requires more than
100 megabytes of system memory. If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-cursor.allowDiskUse" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
allowDiskUse()
</code>
</span>
</a>
was omitted
<em>
and
</em>
the operation required more than 100 megabytes of
system memory, MongoDB would return an error.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/data-modeling/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Data Modeling
<a class="headerlink leafygreen-ui-1kepx47" href="#data-modeling" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-modeling">
</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="#schema-design--differences-between-relational-and-document-databases" target="_self">
<span>
Schema Design: Differences between Relational and Document Databases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#plan-your-schema" target="_self">
<span>
Plan Your Schema
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#link-related-data" target="_self">
<span>
Link Related Data
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#embedded-data" target="_self">
<span>
Embedded Data
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#references" target="_self">
<span>
References
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#additional-data-modeling-considerations" target="_self">
<span>
Additional Data Modeling Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#data-duplication-and-consistency" target="_self">
<span>
Data Duplication and Consistency
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#indexing" target="_self">
<span>
Indexing
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#hardware-constraints" target="_self">
<span>
Hardware Constraints
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#single-document-atomicity" target="_self">
<span>
Single Document Atomicity
</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">
Data modeling refers to the organization of data within a database and
the links between related entities. Data in MongoDB has a
<strong>
flexible schema model
</strong>
, which means:
</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-document">
Documents
</a>
within a single
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection">
collection
</a>
are not required to have the same set of fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A field's data type can differ between documents within a collection.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Generally, documents in a collection share a similar structure. To
ensure consistency in your data model, you can create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview">
schema
validation rules
<!-- -->
.
</a>
</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">
The flexible data model lets you organize your data to match your
application's needs. MongoDB is a document database, meaning you can
embed related data in object and array fields.
</p>
<p class="leafygreen-ui-1kp3ins">
A flexible schema is useful in the following scenarios:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Your company tracks which department each employee works in. You can
embed department information inside of the
<code class="leafygreen-ui-1l06pbn">
employee
</code>
collection to
return relevant information in a single query.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Your e-commerce application shows the five most recent reviews when
displaying a product. You can store the recent reviews in the same
collection as the product data, and store older reviews in a separate
collection because the older reviews are not accessed as frequently.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Your clothing store needs to create a single-page application for a
product catalog. Different products have different attributes, and
therefore use different document fields. However, you can store all of
the products in the same collection.
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Schema Design: Differences between Relational and Document Databases
<a class="headerlink leafygreen-ui-1kepx47" href="#schema-design--differences-between-relational-and-document-databases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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--differences-between-relational-and-document-databases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When you design a schema for a document database like MongoDB, there are
a couple of important differences from relational databases to consider.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<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>
Relational Database Behavior
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Document Database Behavior
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
You must determine a table's schema before you insert data.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Your schema can change over time as the needs of your application
change.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
You often need to join data from several different tables to
return the data needed by your application.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The flexible data model lets you store data to match the way your
application returns data, and avoid joins. Avoiding joins across
multiple collections improves performance and reduces your
deployment's workload.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Plan Your Schema
<a class="headerlink leafygreen-ui-1kepx47" href="#plan-your-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="plan-your-schema">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To ensure that your data model has a logical structure and achieves
optimal performance, plan your schema prior to using your database at a
production scale. To determine your data model, use the following
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/#std-label-data-modeling-schema-design">
schema design process
<!-- -->
:
</a>
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/schema-design-process/identify-workload/#std-label-data-modeling-identify-workload">
Identify your application's workload
<!-- -->
.
</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/map-relationships/#std-label-data-modeling-map-relationships">
Map relationships between objects in your collections
<!-- -->
.
</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/apply-patterns/#std-label-data-modeling-apply-patterns">
Apply design patterns
<!-- -->
.
</a>
</p>
</li>
</ol>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Link Related Data
<a class="headerlink leafygreen-ui-1kepx47" href="#link-related-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="link-related-data">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When you design your data model in MongoDB, consider the structure of
your documents and the ways your application uses data from related
entities.
</p>
<p class="leafygreen-ui-1kp3ins">
To link related data, you can either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Embed related data within a single document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Store related data in a separate collection and access it with a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-data-modeling-reference" target="_self">
<span>
reference
<!-- -->
.
</span>
</a>
</p>
</li>
</ul>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Embedded Data
<a class="headerlink leafygreen-ui-1kepx47" href="#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="embedded-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Embedded documents store related data in a single document structure. A
document can contain arrays and sub-documents with related data. These
<strong>
denormalized
</strong>
data models allow applications to retrieve related data
in a single database operation.
</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">
For many use cases in MongoDB, the denormalized data model is optimal.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn about the strengths and weaknesses of embedding documents, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
Embedded Data Models
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-data-modeling-reference">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<p class="leafygreen-ui-1kp3ins">
References store relationships between data by including links, called
<strong>
references
</strong>
, from one document to another. For example, a
<code class="leafygreen-ui-1l06pbn">
customerId
</code>
field in an
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection indicates a reference
to a document in a
<code class="leafygreen-ui-1l06pbn">
customers
</code>
collection.
</p>
<p class="leafygreen-ui-1kp3ins">
Applications can resolve these references to access the related data.
Broadly, these are
<em>
normalized
</em>
data models.
</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">
To learn about the strengths and weaknesses of using references, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-referencing">
References
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Data Modeling Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-data-modeling-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-data-modeling-considerations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following factors can impact how you plan your data model.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Data Duplication and Consistency
<a class="headerlink leafygreen-ui-1kepx47" href="#data-duplication-and-consistency" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-duplication-and-consistency">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you embed related data in a single document, you may duplicate data
between two collections. Duplicating data lets your application query
related information about multiple entities in a single query while
logically separating entities in your model.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, a
<code class="leafygreen-ui-1l06pbn">
products
</code>
collection stores the five most recent
reviews in a product document. Those reviews are also stored in a
<code class="leafygreen-ui-1l06pbn">
reviews
</code>
collection, which contains
<em>
all
</em>
product reviews. When a new
review is written, the following writes occur:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The review is inserted into the
<code class="leafygreen-ui-1l06pbn">
reviews
</code>
collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The array of recent reviews in the
<code class="leafygreen-ui-1l06pbn">
products
</code>
collection is updated
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/pop/#mongodb-update-up.-pop">
<code class="leafygreen-ui-1l06pbn">
$pop
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/push/#mongodb-update-up.-push">
<code class="leafygreen-ui-1l06pbn">
$push
</code>
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If the duplicated data is not updated often, then there is minimal
additional work required to keep the two collections consistent.
However, if the duplicated data is updated often, using a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-data-modeling-reference" target="_self">
<span>
reference
</span>
</a>
to link related data may be a
better approach.
</p>
<p class="leafygreen-ui-1kp3ins">
Before you duplicate data, consider the following factors:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
How often the duplicated data needs to be updated.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The performance benefit for reads when data is duplicated.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/handle-duplicate-data/#std-label-data-modeling-duplicate-data">
Handle Duplicate Data
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Indexing
<a class="headerlink leafygreen-ui-1kepx47" href="#indexing" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="indexing">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To improve performance for queries that your application runs
frequently, create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/indexes/#std-label-indexes">
indexes
</a>
on commonly queried fields.
As your application grows,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/measure-index-use/#std-label-indexes-measuring-use">
monitor your deployment's index use
</a>
to ensure that your indexes are still
supporting relevant queries.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Hardware Constraints
<a class="headerlink leafygreen-ui-1kepx47" href="#hardware-constraints" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="hardware-constraints">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you design your schema, consider your deployment's hardware,
especially the amount of available RAM. Larger documents use more RAM,
which may cause your application to read from disk and degrade
performance. When possible, design your schema so only relevant fields
are returned by queries. This practice ensures that your application's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-working-set">
working set
</a>
does not grow unnecessarily large.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Single Document Atomicity
<a class="headerlink leafygreen-ui-1kepx47" href="#single-document-atomicity" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="single-document-atomicity">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In MongoDB, a write operation is atomic on the level of a single
document, even if the operation modifies multiple embedded documents
within a single document. This means that if an update operation
affects several sub-documents, either all of those sub-documents are
updated, or the operation fails entirely and no updates occur.
</p>
<p class="leafygreen-ui-1kp3ins">
A denormalized data model with embedded data combines all related data
in a single document instead of normalizing across multiple documents
and collections. This data model allows atomic operations, in contrast
to a normalized model where operations affect multiple documents.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/data-model-operations/#std-label-data-model-atomicity">
Atomicity
<!-- -->
.
</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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Learn how to structure documents and define your schema in
MongoDB University's
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://learn.mongodb.com/learning-paths/data-modeling-for-mongodb" target="_self">
<span>
Data Modeling
</span>
</a>
course.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$dayOfYear (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-dayofyear--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="-dayofyear--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">
$dayOfYear
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-dayOfYear" 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.-dayOfYear">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the day of the year for a date as a number between 1 and 366.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dayOfYear" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dayOfYear
</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":"{ $dayOfYear: <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">$dayOfYear</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":"{ $dayOfYear: 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">$dayOfYear</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>
1
</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":"{ $dayOfYear: { 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">$dayOfYear</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>
7
</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":"{ $dayOfYear: {\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">$dayOfYear</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>
226
</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":"{ $dayOfYear: 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">$dayOfYear</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>
311
</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":"{ $dayOfYear: {\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">$dayOfYear</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>
310
</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":"{ $dayOfYear: \"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">$dayOfYear</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":"{ $dayOfYear: 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">$dayOfYear</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":"{ $dayOfYear: \"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">$dayOfYear</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>
$dayOfYear 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 document:
</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.-dayOfYear" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dayOfYear
</code>
</span>
</a>
and other date
expressions 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=""><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="leafygreen-ui-1wr1lm6"><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/operator/aggregation/strcasecmp/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$strcasecmp (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-strcasecmp--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="-strcasecmp--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">
$strcasecmp
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-strcasecmp" 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.-strcasecmp">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Performs case-insensitive comparison of two strings. Returns
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
1 if first string is "greater than" the second string.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
0 if the two strings are equal.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
-1 if the first string is "less than" the second string.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-strcasecmp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$strcasecmp
</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":"{ $strcasecmp: [ <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">$strcasecmp</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 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 strings. 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.-strcasecmp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$strcasecmp
</code>
</span>
</a>
only has
<!-- -->
a well-defined behavior for strings of ASCII characters.
</p>
<p class="leafygreen-ui-1kp3ins">
For a case sensitive comparison, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/cmp/#mongodb-expression-exp.-cmp">
<code class="leafygreen-ui-1l06pbn">
$cmp
</code>
.
</a>
</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 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":"db.inventory.insertMany( [\n { \"_id\" : 1, \"item\" : \"ABC1\", quarter: \"13Q1\", \"description\" : \"product 1\" },\n { \"_id\" : 2, \"item\" : \"ABC2\", quarter: \"13Q4\", \"description\" : \"product 2\" },\n { \"_id\" : 3, \"item\" : \"XYZ1\", quarter: \"14Q2\", \"description\" : 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">inventory</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">"ABC1"</span>, <span class="lg-highlight-attr">quarter</span>: <span class="lg-highlight-string">"13Q1"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 1"</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">quarter</span>: <span class="lg-highlight-string">"13Q4"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 2"</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">"XYZ1"</span>, <span class="lg-highlight-attr">quarter</span>: <span class="lg-highlight-string">"14Q2"</span>, <span class="lg-highlight-string">"description"</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>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-strcasecmp" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$strcasecmp
</code>
</span>
</a>
operator to
perform case-insensitive comparison of the
<code class="leafygreen-ui-1l06pbn">
quarter
</code>
field value to
the string
<code class="leafygreen-ui-1l06pbn">
"13q4"
</code>
:
</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 item: 1,\n comparisonResult: { $strcasecmp: [ \"$quarter\", \"13q4\" ] }\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">item</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">comparisonResult</span>: <!-- -->{ <span class="lg-highlight-attr">$strcasecmp</span>: <!-- -->[ <span class="lg-highlight-string">"$quarter"</span>, <span class="lg-highlight-string">"13q4"</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, \"item\" : \"ABC1\", \"comparisonResult\" : -1 }\n{ \"_id\" : 2, \"item\" : \"ABC2\", \"comparisonResult\" : 0 }\n{ \"_id\" : 3, \"item\" : \"XYZ1\", \"comparisonResult\" : 1 }","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">"_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">"comparisonResult"</span> <!-- -->: <!-- -->-<span class="lg-highlight-number">1</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">"comparisonResult"</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">3</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"XYZ1"</span>, <span class="lg-highlight-string">"comparisonResult"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/Bulk.find.deleteOne/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Bulk.find.deleteOne()
<a class="headerlink leafygreen-ui-1kepx47" href="#bulk.find.deleteone--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.deleteone--">
</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">
Bulk.find.deleteOne()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-Bulk.find.deleteOne" 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.deleteOne">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a single document remove operation to a bulk operations list.
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 document to remove.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.deleteOne()
</code>
only deletes the first matching document.
To remove multiple documents, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.delete/#mongodb-method-Bulk.find.delete">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.delete()
</code>
.
</a>
</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 has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"Bulk.find( <filter> ).deleteOne()","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">Bulk</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <span class="lg-highlight-tag lg-highlight-xml"><</span><span class="lg-highlight-name lg-highlight-tag lg-highlight-xml">filter</span><span class="lg-highlight-tag lg-highlight-xml"> </span><span class="lg-highlight-attr lg-highlight-tag lg-highlight-xml">document</span><span class="lg-highlight-tag lg-highlight-xml">></span><span class="lg-highlight-xml"> ).deleteOne()</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 details on the
<code class="leafygreen-ui-1l06pbn">
find()
</code>
method see:
<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>
</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 the
<code class="leafygreen-ui-1l06pbn">
music
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.music.insertMany( [\n { artist: \"DOA\", genre: \"punk\" },\n { artist: \"Rick Astley\", genre: \"pop\" },\n { artist: \"Black Flag\", genre: \"punk\" },\n { artist: \"Justin Bieber\", genre: \"pop\" }\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">music</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">artist</span>: <span class="lg-highlight-string">"DOA"</span>, <span class="lg-highlight-attr">genre</span>: <span class="lg-highlight-string">"punk"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">artist</span>: <span class="lg-highlight-string">"Rick Astley"</span>, <span class="lg-highlight-attr">genre</span>: <span class="lg-highlight-string">"pop"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">artist</span>: <span class="lg-highlight-string">"Black Flag"</span>, <span class="lg-highlight-attr">genre</span>: <span class="lg-highlight-string">"punk"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">artist</span>: <span class="lg-highlight-string">"Justin Bieber"</span>, <span class="lg-highlight-attr">genre</span>: <span class="lg-highlight-string">"pop"</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 example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
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.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Searches for the genre
<code class="leafygreen-ui-1l06pbn">
pop
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Deletes
<code class="leafygreen-ui-1l06pbn">
Rick Astley
</code>
, the first matching pop artist, from the
collection.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var bulk = db.music.initializeOrderedBulkOp();\nbulk.find( { \"genre\": \"pop\" } ).deleteOne();\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">music</span>.<span class="lg-highlight-title lg-highlight-function">initializeOrderedBulkOp</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-string">"genre"</span>: <span class="lg-highlight-string">"pop"</span> } ).<span class="lg-highlight-title lg-highlight-function">deleteOne</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>
<p class="leafygreen-ui-1kp3ins">
To delete all
<code class="leafygreen-ui-1l06pbn">
"pop"
</code>
music, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Bulk.find.delete/#mongodb-method-Bulk.find.delete">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.delete()
</code>
</a>
instead.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/Bulk.find/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Bulk.find()
<a class="headerlink leafygreen-ui-1kepx47" href="#bulk.find--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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--">
</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(<query>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-Bulk.find" 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">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Specifies a query condition for an update or a remove operation.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</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>
<code class="leafygreen-ui-1l06pbn">
query
</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 a query condition using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors">
Query Selectors
</a>
to select
documents for an update or a remove operation. To specify all documents,
use an empty document
<code class="leafygreen-ui-1l06pbn">
{}
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
With update operations, the sum of the query document 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>
<p class="leafygreen-ui-1kp3ins">
With remove operations, the query 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>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</span>
</a>
with the following write operations:
</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/Bulk.find.removeOne/#mongodb-method-Bulk.find.removeOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.removeOne()
</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.remove/#mongodb-method-Bulk.find.remove">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.remove()
</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.replaceOne/#mongodb-method-Bulk.find.replaceOne">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.replaceOne()
</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.find.update/#mongodb-method-Bulk.find.update">
<code class="leafygreen-ui-1l06pbn">
Bulk.find.update()
</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 a remove operation and an update
operation to the list of operations. The remove operation and the
update operation use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find()
</code>
</span>
</a>
method to specify a
condition for their respective actions:
</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\" } ).delete();\nbulk.find( { status: \"P\" } ).update( { $set: { points: 0 } } )\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">delete</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>( <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-number">0</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>
<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.execute/#mongodb-method-Bulk.execute">
<code class="leafygreen-ui-1l06pbn">
Bulk.execute()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/Bulk.find.replaceOne/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Bulk.find.replaceOne()
<a class="headerlink leafygreen-ui-1kepx47" href="#bulk.find.replaceone--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.replaceone--">
</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.replaceOne(<document>)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-Bulk.find.replaceOne" 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.replaceOne">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a single document replacement operation to a bulk operations
list. 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 document to replace. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find.replaceOne" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find.replaceOne()
</code>
</span>
</a>
method limits the replacement to a
single document.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find.replaceOne" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Bulk.find.replaceOne()
</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>
<code class="leafygreen-ui-1l06pbn">
replacement
</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">
A replacement document that completely replaces the existing
document. Contains only field and value pairs.
</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 replacement 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>
<p class="leafygreen-ui-1kp3ins">
To specify an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upsert
</a>
for this operation, see
<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>
</p>
<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>
</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
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-Bulk.find.replaceOne" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replaceOne()
</code>
</span>
</a>
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( { item: \"abc123\" } ).replaceOne( { item: \"abc123\", status: \"P\", points: 100 } );\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">item</span>: <span class="lg-highlight-string">"abc123"</span> } ).<span class="lg-highlight-title lg-highlight-function">replaceOne</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"abc123"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"P"</span>, <span class="lg-highlight-attr">points</span>: <span class="lg-highlight-number">100</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>
<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.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>
|
https://www.mongodb.com/docs/manual/reference/command/rotateCertificates/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
rotateCertificates
<a class="headerlink leafygreen-ui-1kepx47" href="#rotatecertificates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rotatecertificates">
</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="#output" target="_self">
<span>
Output
</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="#logging" target="_self">
<span>
Logging
</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>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.rotateCertificates" 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.rotateCertificates">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Rotates the currently used
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-rotated-certs-command" target="_self">
<span>
TLS certificates
</span>
</a>
for a
<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>
to use the updated values for these
certificates defined in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
<!-- -->
.
</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 rotateCertificates: 1,\n message: \"<optional>\"\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">rotateCertificates</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"<optional log message>"</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">
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 optional 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>
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">
message
</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.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</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.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
command returns a document with
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">
ok
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
bool
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the command's execution status.
<code class="leafygreen-ui-1l06pbn">
true
</code>
on success, or
<code class="leafygreen-ui-1l06pbn">
false
</code>
if an error occurred. If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, an
<code class="leafygreen-ui-1l06pbn">
errmsg
</code>
field
is additionally provided with a detailed error message.
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rotated-certs-command">
</span>
<p class="leafygreen-ui-1kp3ins">
Rotation includes the following certificates:
</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-net.tls.certificateKeyFile">
<code class="leafygreen-ui-1l06pbn">
TLS Certificates
</code>
</a>
</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-net.tls.CRLFile">
<code class="leafygreen-ui-1l06pbn">
CRL (Certificate Revocation List) files
</code>
</a>
(on Linux and Windows platforms)
</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-net.tls.CAFile">
<code class="leafygreen-ui-1l06pbn">
CA (Certificate Authority) files
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To rotate one or more of these certificates:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Replace the certificate or certificates you wish to rotate on the
filesystem, noting the following constraints:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each new certificate must have the
<em>
same filename
</em>
and
<em>
same filepath
</em>
as the certificate it is replacing.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If rotating an encrypted
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFile">
<code class="leafygreen-ui-1l06pbn">
TLS Certificate
</code>
</a>
, its password must be the same as
the password for the old certificate (as specified to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFilePassword">
<code class="leafygreen-ui-1l06pbn">
certificateKeyFilePassword
</code>
</a>
configuration file
setting). Certificate rotation does not support the interactive
password prompt.
</p>
</li>
</ul>
</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
<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>
instance that you wish to perform certificate
rotation on.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Run the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
command to rotate the
certificates 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>
or
<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>
</ol>
<p class="leafygreen-ui-1kp3ins">
When certificate rotation takes place:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Existing connections 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>
instance are not terminated, and will continue
to use the old certificates.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Any new connections will use the new certificates.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you have configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ocspEnabled">
<code class="leafygreen-ui-1l06pbn">
OCSP
</code>
</a>
for your
deployment, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
command will also fetch
stapled OCSP responses during rotation.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
command may be run on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
regardless of replication
status.
</p>
<p class="leafygreen-ui-1kp3ins">
Only one instance of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.rotateCertificates/#mongodb-method-db.rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</a>
or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
may run on each
<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>
process at a time. Attempting to initiate a second
instance while one is already running will result in an error.
</p>
<p class="leafygreen-ui-1kp3ins">
Incorrect, expired, revoked, or missing certificate files will cause the
certificate rotation to fail, but will not invalidate the existing
TLS configuration or terminate the 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>
process.
</p>
<p class="leafygreen-ui-1kp3ins">
If 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>
is running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
</a>
set
to
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
will fail and write
a warning message to the log file.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Logging
<a class="headerlink leafygreen-ui-1kepx47" href="#logging" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="logging">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
On successful rotation, the subject names, thumbprints, and the
validity period of the server and cluster certificate thumbprints are
logged to the configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-destinations">
log destination
</a>
. If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
auditing
</a>
is
enabled, this information is also written to the audit log.
</p>
<p class="leafygreen-ui-1kp3ins">
On Linux and Windows platforms, if a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.CRLFile">
<code class="leafygreen-ui-1l06pbn">
CRL file
</code>
</a>
is present, its thumbprint and validity period are
also logged to these locations.
</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-rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-security-user-actions">
action
</a>
in order to use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</span>
</a>
command
<!-- -->
. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
action is part of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-hostManager">
<code class="leafygreen-ui-1l06pbn">
hostManager
</code>
</a>
role.
</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 following operation rotates the certificates on 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, after having made the appropriate
updates to the configuration file to specify the updated certificate
information:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { rotateCertificates: 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">rotateCertificates</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 performs the same as above, but also writes a custom log
message at rotation time to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-destinations">
log file
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
audit file
<!-- -->
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { rotateCertificates: 1, message: \"Rotating certificates\" } )","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">rotateCertificates</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">message</span>: <span class="lg-highlight-string">"Rotating certificates"</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/core/sharding-change-shard-key-value/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Change a Document's Shard Key Value
<a class="headerlink leafygreen-ui-1kepx47" href="#change-a-document-s-shard-key-value" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-a-document-s-shard-key-value">
</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>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
You can update a document's shard key value unless the shard key field is the
immutable
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field.
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
When updating the shard key value
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong>
must
</strong>
be 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>
. Do
<strong>
not
</strong>
issue the
operation directly on the shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong>
must
</strong>
run either in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
transaction
</a>
or as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/">
retryable write
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong>
must
</strong>
include an equality condition on the full shard
key in the query filter. For example, consider a
<code class="leafygreen-ui-1l06pbn">
messages
</code>
collection that uses
<code class="leafygreen-ui-1l06pbn">
{ activityid: 1, userid : 1 }
</code>
as the
shard key. To update the shard key value for a document, you must
include
<code class="leafygreen-ui-1l06pbn">
activityid: <value>, userid: <value>
</code>
in the query
filter. You can include additional fields in the query as
appropriate.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See also the specific write command/methods for additional
operation-specific requirements when run against a sharded
collection.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To update a shard key value, use the following operations:
</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>
Command
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Method
</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/command/update/#std-label-command-update-shard-key-modification">
update
</a>
with
<code class="leafygreen-ui-1l06pbn">
multi: false
</code>
</div>
</div>
</td>
<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/method/db.collection.replaceOne/#std-label-replaceOne-shard-key-modification">
db.collection.replaceOne()
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-shard-key-modification">
db.collection.updateOne()
</a>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To set to a non-
<code class="leafygreen-ui-1l06pbn">
null
</code>
value, the update
<strong class="css-4dei7l">
must
</strong>
be
performed either inside a transaction or as a retryable write.
</p>
</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/command/findAndModify/#std-label-cmd-findAndModify-sharded-collection">
findAndModify
</a>
</div>
</div>
</td>
<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/method/db.collection.findOneAndReplace/#std-label-findOneAndReplace-shard-key-modification">
db.collection.findOneAndReplace()
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#std-label-findOneAndUpdate-shard-key-modification">
db.collection.findOneAndUpdate()
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findAndModify/#std-label-method-findAndModify-sharded-collection">
db.collection.findAndModify()
</a>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To set to a non-
<code class="leafygreen-ui-1l06pbn">
null
</code>
value, the update
<strong class="css-4dei7l">
must
</strong>
be
performed either inside a transaction or as a retryable write.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<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 class="line-block">
<div class="line">
<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>
</div>
<div class="line">
<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>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the shard key modification results in moving the document to
another shard, you cannot specify more than one shard key
modification in the bulk operation; the batch size has to be 1.
</p>
<p class="leafygreen-ui-1kp3ins">
If the shard key modification does not result in moving the
document to another shard, you can specify multiple shard
key modification in the bulk operation.
</p>
<p class="leafygreen-ui-1kp3ins">
To set to a non-
<code class="leafygreen-ui-1l06pbn">
null
</code>
value, the operation
<strong class="css-4dei7l">
must
</strong>
be
performed either inside a transaction or as a retryable write.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Documents in sharded collections can be missing the shard key fields.
Take precaution to avoid accidentally removing the shard key when changing
a document's shard key value.
</p>
</div>
</div>
<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 which is sharded on the
<code class="leafygreen-ui-1l06pbn">
location
</code>
field. The collection contains a document with the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
<code class="leafygreen-ui-1l06pbn">
12345
</code>
and the
<code class="leafygreen-ui-1l06pbn">
location
</code>
<code class="leafygreen-ui-1l06pbn">
""
</code>
. To update the field value for
this document, you can run the following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.updateOne(\n { _id: 12345, location: \"\" },\n { $set: { location: \"New York\"} }\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">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">12345</span>, <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">""</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">location</span>: <span class="lg-highlight-string">"New York"</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>
<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-set-missing-shard-key-fields/#std-label-shard-key-missing-set">
Set Missing Shard Key Fields
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/configureCollectionBalancing/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
configureCollectionBalancing
<a class="headerlink leafygreen-ui-1kepx47" href="#configurecollectionbalancing" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="configurecollectionbalancing">
</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="#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">
configureCollectionBalancing
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.configureCollectionBalancing" 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.configureCollectionBalancing">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.3
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Configures balancer settings for a sharded collection, such as
setting the chunk size for and defragmenting the collection.
</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 configureCollectionBalancing: \"<db>.<collection>\",\n chunkSize: <num>,\n defragmentCollection: <bool>\n enableAutoMerger: <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">configureCollectionBalancing</span>: <span class="lg-highlight-string">"<db>.<collection>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunkSize</span>: <<!-- -->num<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">defragmentCollection</span>: <<!-- -->bool<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">enableAutoMerger</span>: <<!-- -->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>
<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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.configureCollectionBalancing" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
configureCollectionBalancing
</code>
</span>
</a>
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: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>
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">
configureCollectionBalancing
</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>
The name of the database and sharded collection to configure.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
chunkSize
</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
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Sets the chunk size in MiB for the collection. The
recommended size is 256, 512, or larger. For details on default
behavior, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-chunksize-not-specified" target="_self">
<span>
Default Behavior When chunkSize Is Not Specified
<!-- -->
.
</span>
</a>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
defragmentCollection
</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
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Causes the balancer to defragment the collection.
Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
enableAutoMerger
</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
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Whether or not the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/automerger-concept/#std-label-automerger-concept">
AutoMerger
</a>
takes this collection into account.
Defaults to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-data-partitioning">
Data Partitioning with Chunks
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To configure the chunk defragmentation throttling time parameter, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.chunkDefragmentationThrottlingMS">
<code class="leafygreen-ui-1l06pbn">
chunkDefragmentationThrottlingMS
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To learn about defragmenting sharded collections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/defragment-sharded-collections/#std-label-defragment-sharded-collections">
Defragment Sharded Collections
<!-- -->
.
</a>
</p>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-chunksize-not-specified">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Default Behavior When chunkSize Is Not Specified
<a class="headerlink leafygreen-ui-1kepx47" href="#default-behavior-when-chunksize-is-not-specified" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-behavior-when-chunksize-is-not-specified">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you do not specify
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
for a collection and no custom size
has been set previously, the global default
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
is
used for balancing.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specifying chunkSize: 0
<a class="headerlink leafygreen-ui-1kepx47" href="#specifying-chunksize--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="specifying-chunksize--0">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.configureCollectionBalancing" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
configureCollectionBalancing
</code>
</span>
</a>
with
<code class="leafygreen-ui-1l06pbn">
chunkSize: 0
</code>
, the per-collection
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
is reset and the
global default
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
is used for balancing.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on configuring default
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/modify-chunk-size-in-sharded-cluster/#std-label-tutorial-modifying-range-size">
Modify Range Size in a Sharded Cluster
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Default Behavior When enableAutoMerger Is Not Specified
<a class="headerlink leafygreen-ui-1kepx47" href="#default-behavior-when-enableautomerger-is-not-specified" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-behavior-when-enableautomerger-is-not-specified">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you do not specify
<code class="leafygreen-ui-1l06pbn">
enableAutoMerger
</code>
for a collection and no
custom automerging behavior has been previously set, it
defaults to
<code class="leafygreen-ui-1l06pbn">
true
</code>
and will be taken into account by the
AutoMerger.
</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">
Configure Chunk Size
<a class="headerlink leafygreen-ui-1kepx47" href="#configure-chunk-size" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-chunk-size">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To change the chunk size for a sharded collection, use
the
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
option:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n configureCollectionBalancing: \"test.students\",\n chunkSize: 256\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">configureCollectionBalancing</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunkSize</span>: <span class="lg-highlight-number">256</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">
Use this command to change the chunk size for the given collection.
</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">
By default, MongoDB cannot move a chunk if the number of documents in
the chunk is greater than 2 times the result of dividing the
configured chunk size by the average document size.
</p>
<p class="leafygreen-ui-1kp3ins">
To find the average document size, see the
<code class="leafygreen-ui-1l06pbn">
avgObjSize
</code>
field in the
output of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
method.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-range-size">
Range Size
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Defragment Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#defragment-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="defragment-collections">
</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">
We do not recommend using
<code class="leafygreen-ui-1l06pbn">
defragmentCollection
</code>
to defragment sharded
collections for MongoDB 6.0.0 to 6.0.3 and MongoDB 6.1.0 to 6.1.1, as the
defragmentation process on these releases can make databases and collections
unavailable for extended periods of time.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To tell the balancer to defragment a sharded collection, use the
<code class="leafygreen-ui-1l06pbn">
defragmentCollection
</code>
option:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n configureCollectionBalancing: \"test.students\",\n defragmentCollection: 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">configureCollectionBalancing</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">defragmentCollection</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">
Use this command to have the balancer defragment a sharded collection.
To monitor the chunk defragmentation process, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/balancerCollectionStatus/#mongodb-dbcommand-dbcmd.balancerCollectionStatus">
<code class="leafygreen-ui-1l06pbn">
balancerCollectionStatus
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more about defragmenting sharded collections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/defragment-sharded-collections/#std-label-defragment-sharded-collections">
Defragment Sharded Collections
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Reconfigure and Defragment Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#reconfigure-and-defragment-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="reconfigure-and-defragment-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To defragment a sharded collection while updating the chunk size, use
the
<code class="leafygreen-ui-1l06pbn">
defragmentCollection
</code>
option and the
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
option
together:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n configureCollectionBalancing: \"test.students\",\n chunkSize: 512,\n defragmentCollection: 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">configureCollectionBalancing</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunkSize</span>: <span class="lg-highlight-number">512</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">defragmentCollection</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">
Disable the AutoMerger on a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-the-automerger-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="disable-the-automerger-on-a-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To explicitly disable the AutoMerger on a collection,
set the
<code class="leafygreen-ui-1l06pbn">
enableAutoMerger
</code>
option to
<code class="leafygreen-ui-1l06pbn">
false
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n configureCollectionBalancing: \"test.students\",\n enableAutoMerger: 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">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">configureCollectionBalancing</span>: <span class="lg-highlight-string">"test.students"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">enableAutoMerger</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>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$median (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-median--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="-median--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="#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>
<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="group">
<dt>
<code class="leafygreen-ui-1l06pbn">
$median
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-median" 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-group-grp.-median">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns an approximation of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-median">
median
</a>
, the 50th
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-percentile">
percentile
</a>
, as a scalar value.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
as an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#std-label-accumulators-group">
accumulator
</a>
in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
stage or as
an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggegation expression
<!-- -->
.
</a>
</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 syntax for
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $median: {\n input: <number>,\n method: <string>\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">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method</span>: <<!-- -->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>
</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">
<code class="leafygreen-ui-1l06pbn">
$median
</code>
takes the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:17%"/>
<col style="width:17%"/>
<col style="width:51%"/>
</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">
input
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Expression
</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>
<code class="leafygreen-ui-1l06pbn">
$median
</code>
calculates the 50th percentile value of this data.
<code class="leafygreen-ui-1l06pbn">
input
</code>
must be a field name or an expression that evaluates to
a numeric type. If the expression cannot be converted to a
numeric type, the
<code class="leafygreen-ui-1l06pbn">
$median
</code>
calculation ignores it.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
method
</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>
The method that
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
uses to calculate the 50th percentile
value. The method must be
<code class="leafygreen-ui-1l06pbn">
'approximate'
</code>
.
</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">
You can use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in:
</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/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
stages as an accumulator
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stages as an accumulator
</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>
stages as an aggregation expression
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$median
</code>
has the following characteristics as an accumulator, it:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Calculates a single result for all the documents in the stage.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://arxiv.org/abs/1902.04023" rel="noopener noreferrer">
<span>
t-digest
</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>
algorithm to
calculate approximate, percentile based metrics.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Uses approximate methods to scale to large volumes of data.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$median
</code>
has the following characteristics as an aggregation
expression, it:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Accepts an array as input
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Calculates a separate result for each input document
</p>
</li>
</ul>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Type of Operation
<a class="headerlink leafygreen-ui-1kepx47" href="#type-of-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="type-of-operation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In a
<code class="leafygreen-ui-1l06pbn">
$group
</code>
stage,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is an accumulator and calculates
a value for all documents in the window.
</p>
<p class="leafygreen-ui-1kp3ins">
In a
<code class="leafygreen-ui-1l06pbn">
$project
</code>
stage,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is an aggregation expression and
calculates values for each document.
</p>
<p class="leafygreen-ui-1kp3ins">
In
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
stages,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
returns a result
for each document like an aggregation expression, but the results are
computed over groups of documents like an accumulator.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Calculation Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#calculation-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="calculation-considerations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In
<code class="leafygreen-ui-1l06pbn">
$group
</code>
stages,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
always uses an approximate
calculation method.
</p>
<p class="leafygreen-ui-1kp3ins">
In
<code class="leafygreen-ui-1l06pbn">
$project
</code>
stages,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
might use the discrete
calculation method even when the approximate method is specified.
</p>
<p class="leafygreen-ui-1kp3ins">
In
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
stages, the workload determines the calculation
method that
<code class="leafygreen-ui-1l06pbn">
$median
</code>
uses.
</p>
<p class="leafygreen-ui-1kp3ins">
The computed percentiles
<code class="leafygreen-ui-1l06pbn">
$median
</code>
returns might vary, even on the
same datasets. This is because the algorithm calculates approximate
values.
</p>
<p class="leafygreen-ui-1kp3ins">
Duplicate samples can cause ambiguity. If there are a large number of
duplicates, the percentile values may not represent the actual sample
distribution. Consider a data set where all the samples are the same.
All of the values in the data set fall at or below any percentile. A
"50th percentile" value would actually represent either 0 or 100 percent
of the samples.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Array Input
<a class="headerlink leafygreen-ui-1kepx47" href="#array-input" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="array-input">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
as an aggregation expression in a
<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, you can use an array as input.
<code class="leafygreen-ui-1l06pbn">
$median
</code>
ignores non-numeric array values.
</p>
<p class="leafygreen-ui-1kp3ins">
The syntax is:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $median:\n {\n input: [ <expression1,>, ..., <expressionn> ],\n method: <string>\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">$median</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <!-- -->[ <<!-- -->expression1<!-- -->, <<!-- -->expression2<!-- -->><!-- -->,<!-- --> <!-- -->...<!-- -->, <<!-- -->expressionN<!-- -->> <!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method</span>: <<!-- -->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>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Window Functions
<a class="headerlink leafygreen-ui-1kepx47" href="#window-functions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="window-functions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
A window function lets you calculate results over a moving "window" of
neighboring documents. As each document passes though the pipeline, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Recomputes the set of documents in the current window
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
calculates a value for all documents in the set
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
returns a single value for that document
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You can use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in a
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
stage to calculate
rolling statistics for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-landing">
time series
</a>
or
other related data.
</p>
<p class="leafygreen-ui-1kp3ins">
When you use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in a
<code class="leafygreen-ui-1l06pbn">
$setWindowField
</code>
stage, the
<code class="leafygreen-ui-1l06pbn">
input
</code>
value must be a field name. If you enter an array instead of a
field name, the operation fails.
</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>
<p class="leafygreen-ui-1kp3ins">
The following examples use the
<code class="leafygreen-ui-1l06pbn">
testScores
</code>
collection. Create the
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.insertMany( [\n { studentId: \"2345\", test01: 62, test02: 81, test03: 80 },\n { studentId: \"2356\", test01: 60, test02: 83, test03: 79 },\n { studentId: \"2358\", test01: 67, test02: 82, test03: 78 },\n { studentId: \"2367\", test01: 64, test02: 72, test03: 77 },\n { studentId: \"2369\", test01: 60, test02: 53, test03: 72 }\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">testScores</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">studentId</span>: <span class="lg-highlight-string">"2345"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">62</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">81</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">80</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2356"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">60</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">83</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">79</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2358"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">67</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">82</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">78</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2367"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">64</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">72</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">77</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">"2369"</span>, <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">60</span>, <span class="lg-highlight-attr">test02</span>: <span class="lg-highlight-number">53</span>, <span class="lg-highlight-attr">test03</span>: <span class="lg-highlight-number">72</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">
Use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
as an Accumulator
<a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-as-an-accumulator" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-operatorname-as-an-accumulator">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an accumulator that calculates the median value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n {\n $group: {\n _id: null,\n test01_median: {\n $median: {\n input: \"$test01\",\n method: 'approximate'\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">testScores</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">$group</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-literal">null</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">test01_median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$test01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</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":"{ _id: null, test01_median: 62 }","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">_id</span>: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">62</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field value is
<code class="leafygreen-ui-1l06pbn">
null
</code>
so
<code class="leafygreen-ui-1l06pbn">
$group
</code>
selects all the
documents in the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$median
</code>
accumulator takes its input from the
<code class="leafygreen-ui-1l06pbn">
test01
</code>
field.
<code class="leafygreen-ui-1l06pbn">
$median
</code>
calculates the median value for the field,
<code class="leafygreen-ui-1l06pbn">
62
</code>
in this example.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in a
<code class="leafygreen-ui-1l06pbn">
$project
</code>
Stage
<a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-in-a--project-stage" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-operatorname-in-a--project-stage">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
In a
<code class="leafygreen-ui-1l06pbn">
$group
</code>
stage,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is an accumulator and calculates
a single value for all documents. In a
<code class="leafygreen-ui-1l06pbn">
$project
</code>
stage,
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is an aggregation expression and calculates values for
each document.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use a field name or an array as input in a
<code class="leafygreen-ui-1l06pbn">
$project
</code>
stage.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n {\n $project: {\n _id: 0,\n studentId: 1,\n testMedians: {\n $median: {\n input: [ \"$test01\", \"$test02\", \"$test03\" ],\n method: 'approximate'\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">testScores</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>: <!-- -->{</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">studentId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">testMedians</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <!-- -->[ <span class="lg-highlight-string">"$test01"</span>, <span class="lg-highlight-string">"$test02"</span>, <span class="lg-highlight-string">"$test03"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</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":"{ studentId: '2345', testMedians: 80 },\n{ studentId: '2356', testMedians: 79 },\n{ studentId: '2358', testMedians: 78 },\n{ studentId: '2367', testMedians: 72 },\n{ studentId: '2369', testMedians: 60 }","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">studentId</span>: <span class="lg-highlight-string">'2345'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">80</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2356'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">79</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2358'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">78</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2367'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">72</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2369'</span>, <span class="lg-highlight-attr">testMedians</span>: <span class="lg-highlight-number">60</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
$median
</code>
is an aggregation expression there is a result for
each
<code class="leafygreen-ui-1l06pbn">
studentId
</code>
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in a
<code class="leafygreen-ui-1l06pbn">
$setWindowField
</code>
Stage
<a class="headerlink leafygreen-ui-1kepx47" href="#use-operatorname-in-a--setwindowfield-stage" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-operatorname-in-a--setwindowfield-stage">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To base your percentile values on local data trends, use
<code class="leafygreen-ui-1l06pbn">
$median
</code>
in a
<code class="leafygreen-ui-1l06pbn">
$setWindowField
</code>
aggregation pipeline stage.
</p>
<p class="leafygreen-ui-1kp3ins">
This example creates a window to filter scores:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.testScores.aggregate( [\n {\n $setWindowFields: {\n sortBy: { test01: 1 },\n output: {\n test01_median: {\n $median: {\n input: \"$test01\",\n method: 'approximate'\n },\n window: {\n range: [ -3, 3 ]\n }\n }\n }\n }\n },\n {\n $project: {\n _id: 0,\n studentId: 1,\n test01_median: 1\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">testScores</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">$setWindowFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">test01</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">test01_median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$median</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$test01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">method</span>: <span class="lg-highlight-string">'approximate'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">window</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">3</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><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">_id</span>: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">test01_median</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">] )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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":"{ studentId: '2356', test01_median: 60 },\n{ studentId: '2369', test01_median: 60 },\n{ studentId: '2345', test01_median: 60 },\n{ studentId: '2367', test01_median: 64 },\n{ studentId: '2358', test01_median: 64 }","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">studentId</span>: <span class="lg-highlight-string">'2356'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2369'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2345'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">60</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2367'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">64</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">studentId</span>: <span class="lg-highlight-string">'2358'</span>, <span class="lg-highlight-attr">test01_median</span>: <span class="lg-highlight-number">64</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In this example, the median calculation for each document also
incorporates data from the three documents before and after it.
</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">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/percentile/#mongodb-group-grp.-percentile">
<code class="leafygreen-ui-1l06pbn">
$percentile
</code>
</a>
operator is a more general
version of the
<code class="leafygreen-ui-1l06pbn">
$median
</code>
operator that allows you to set one or
more percentile values.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on window functions, see:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/planCacheClearFilters/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
planCacheClearFilters
<a class="headerlink leafygreen-ui-1kepx47" href="#plancacheclearfilters" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="plancacheclearfilters">
</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="#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">
planCacheClearFilters
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.planCacheClearFilters" 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.planCacheClearFilters">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Removes
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
on a collection.
Although index filters only exist for the duration of the server
process and do not persist after shutdown, you can also clear
existing index filters with the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.planCacheClearFilters" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
planCacheClearFilters
</code>
</span>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-plan-cache-query-shape">
plan cache query shape
</a>
to remove a specific index filter.
Omit the plan cache query shape to clear all index filters on a collection.
</p>
</dd>
</dl>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Settings
<a class="headerlink leafygreen-ui-1kepx47" href="#query-settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-settings">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, use query settings instead of adding
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
. Index filters are deprecated
starting in MongoDB 8.0.
</p>
<p class="leafygreen-ui-1kp3ins">
Query settings have more functionality than index filters. Also, index
filters aren't persistent and you cannot easily create index filters for
all cluster nodes. To add query settings and explore examples, 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>
</section>
</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 planCacheClearFilters: <collection>,\n query: <query>,\n sort: <sort>,\n projection: <projection>,\n collation: { <collation> },\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">planCacheClearFilters</span>: <<!-- -->collection<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- --><query pattern>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sort: <sort specification>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> projection: <projection specification>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: { <collation> },</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 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: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">
planCacheClearFilters
</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 collection to remove the index filters from.
</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">
query
</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 query predicate for the index filter to
remove. If omitted, the command clears all index filters from the
collection.
</p>
<p class="leafygreen-ui-1kp3ins">
The values in the
<code class="leafygreen-ui-1l06pbn">
query
</code>
predicate do not:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Determine the plan cache query shape.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Need to match the values returned by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheListFilters/#mongodb-dbcommand-dbcmd.planCacheListFilters">
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters
</code>
.
</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">
sort
</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 sort for the index filter to remove, if any.
</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">
projection
</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 projection for the index filter to remove, if any.
</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">
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-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">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>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, an index filter uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
previously set using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheSetFilter/#mongodb-dbcommand-dbcmd.planCacheSetFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheSetFilter
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, use query settings instead of adding
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
. Index filters are deprecated
starting in MongoDB 8.0.
</p>
<p class="leafygreen-ui-1kp3ins">
Query settings have more functionality than index filters. Also, index
filters aren't persistent and you cannot easily create index filters for
all cluster nodes. To add query settings and explore examples, 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>
</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">
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">
A user must have access that includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-planCacheIndexFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheIndexFilter
</code>
</a>
action.
</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">
Clear Specific Index Filter on Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#clear-specific-index-filter-on-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="clear-specific-index-filter-on-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection contains the following index filters:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"query\" : { \"status\" : \"A\" },\n \"sort\" : { \"ord_date\" : -1 },\n \"projection\" : { },\n \"indexes\" : [ { \"status\" : 1, \"cust_id\" : 1 } ]\n}\n\n{\n \"query\" : { \"status\" : \"A\" },\n \"sort\" : { },\n \"projection\" : { },\n \"indexes\" : [ { \"status\" : 1, \"cust_id\" : 1 } ]\n}\n\n{\n \"query\": { \"item\": \"Movie\" },\n \"collation\": { locale: \"en_US\" },\n \"indexes\": [ { \"item\": 1, \"order_date\": 1 , \"quantity\": 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">"query"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sort"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <!-- -->-<span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"projection"</span> <!-- -->: <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexes"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"cust_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"><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-string">"query"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sort"</span> <!-- -->: <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"projection"</span> <!-- -->: <!-- -->{ <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexes"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"cust_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"><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-string">"query"</span>: <!-- -->{ <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-string">"Movie"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"collation"</span>: <!-- -->{ <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">"en_US"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"indexes"</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"item"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"order_date"</span>: <span class="lg-highlight-number">1</span> <!-- -->, <span class="lg-highlight-string">"quantity"</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>
<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 6.0, an index filter uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
previously set using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheSetFilter/#mongodb-dbcommand-dbcmd.planCacheSetFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheSetFilter
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0, use query settings instead of adding
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-plans/#std-label-index-filters">
index filters
</a>
. Index filters are deprecated
starting in MongoDB 8.0.
</p>
<p class="leafygreen-ui-1kp3ins">
Query settings have more functionality than index filters. Also, index
filters aren't persistent and you cannot easily create index filters for
all cluster nodes. To add query settings and explore examples, 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>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following command removes the second index filter only:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n planCacheClearFilters: \"orders\",\n query: { \"status\" : \"A\" }\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">planCacheClearFilters</span>: <span class="lg-highlight-string">"orders"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">
Because the values in the
<code class="leafygreen-ui-1l06pbn">
query
</code>
predicate are insignificant in
determining the plan cache query shape, the following command would also
remove the second index filter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n planCacheClearFilters: \"orders\",\n query: { \"status\" : \"P\" }\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">planCacheClearFilters</span>: <span class="lg-highlight-string">"orders"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"P"</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">
Clear all Index Filters on a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#clear-all-index-filters-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="clear-all-index-filters-on-a-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example clears all index filters on the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n planCacheClearFilters: \"orders\"\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">planCacheClearFilters</span>: <span class="lg-highlight-string">"orders"</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">
Clear Index Filter Containing a Query and a Collation
<a class="headerlink leafygreen-ui-1kepx47" href="#clear-index-filter-containing-a-query-and-a-collation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="clear-index-filter-containing-a-query-and-a-collation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example clears the index filter containing the query on
<code class="leafygreen-ui-1l06pbn">
Movie
</code>
and the collation
<code class="leafygreen-ui-1l06pbn">
en_US
</code>
for the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n planCacheClearFilters: \"orders\",\n query: { item: \"Movie\" },\n collation: { locale: \"en_US\" }\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">planCacheClearFilters</span>: <span class="lg-highlight-string">"orders"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"Movie"</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">"en_US"</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/command/planCacheListFilters/#mongodb-dbcommand-dbcmd.planCacheListFilters">
<code class="leafygreen-ui-1l06pbn">
planCacheListFilters
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/planCacheSetFilter/#mongodb-dbcommand-dbcmd.planCacheSetFilter">
<code class="leafygreen-ui-1l06pbn">
planCacheSetFilter
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/getClientEncryption/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
getClientEncryption()
<a class="headerlink leafygreen-ui-1kepx47" href="#getclientencryption--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="getclientencryption--">
</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>
<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>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
getClientEncryption()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-getClientEncryption" 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-getClientEncryption">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
object for the current database
collection. The
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
object supports explicit
(manual) encryption and decryption of field values for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature">
Client-Side field level encryption
<!-- -->
.
</a>
</p>
<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
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
object for current database connection.
</td>
</tr>
</tbody>
</table>
</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">
<code class="leafygreen-ui-1l06pbn">
getClientEncryption()
</code>
has the following syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getMongo().getClientEncryption();","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">getClientEncryption</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">
Use the
<code class="leafygreen-ui-1l06pbn">
ClientEncryption
</code>
object to access the following
explicit encryption 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/ClientEncryption.createEncryptedCollection/#mongodb-method-ClientEncryption.createEncryptedCollection">
<code class="leafygreen-ui-1l06pbn">
createEncryptedCollection()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ClientEncryption.encrypt/#mongodb-method-ClientEncryption.encrypt">
<code class="leafygreen-ui-1l06pbn">
encrypt()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ClientEncryption.decrypt/#mongodb-method-ClientEncryption.decrypt">
<code class="leafygreen-ui-1l06pbn">
decrypt()
</code>
</a>
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Enable Client-Side Field Level Encryption on Database Connection
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-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="enable-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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
method automatically creates a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
on the
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
field
with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/#std-label-index-type-partial">
partial index
</a>
filter for only
documents where
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
exists.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
creates this index in the key vault collection. This prevents any two
data encryption keys in the same key vault from having the same key
alternative name and therefore avoids ambiguity around which data
encryption key is appropriate for encryption/decryption.
</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 drop the unique index created by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
.
Client-Side Field Level Encryption operations depend on
server-enforced uniqueness of
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
. Removing the index
may lead to unexpected or unpredictable behavior.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example uses a locally managed KMS 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">
Use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-getClientEncryption" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getClientEncryption()
</code>
</span>
</a>
method to
retrieve the client encryption object:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"clientEncryption = encryptedClient.getClientEncryption()","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">clientEncryption <!-- -->= <!-- -->encryptedClient.<span class="lg-highlight-title lg-highlight-function">getClientEncryption</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>
<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 complete documentation on initiating MongoDB connections with
client-side field level encryption enabled, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
<code class="leafygreen-ui-1l06pbn">
Mongo()
</code>
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/audit-message/ocsf/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
OCSF Schema Audit Messages
<a class="headerlink leafygreen-ui-1kepx47" href="#ocsf-schema-audit-messages" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ocsf-schema-audit-messages">
</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="#ocsf-category-mapping" target="_self">
<span>
OCSF Category Mapping
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#ocsf-class-mapping" target="_self">
<span>
OCSF Class Mapping
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#ocsf-type-mapping" target="_self">
<span>
OCSF Type Mapping
</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="#authenticate-action" target="_self">
<span>
Authenticate Action
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#authcheck-action" target="_self">
<span>
AuthCheck Action
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
In the
<span class="leafygreen-ui-vm4wms" tabindex="0">
OCSF
</span>
schema, recorded log messages have this syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"activity_id\" : <int>,\n \"category_uid\" : <int>,\n \"class_uid\" : <int>,\n \"time\" : <int>,\n \"severity_id\" : <int>,\n \"type_uid\" : <int>,\n \"metadata\" : <document>\n \"actor\" : {\n \"user\" : {\n \"type_id\" : <int>,\n \"name\" : <string>,\n \"groups\" : <array>\n }\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"> "activity_id" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "category_uid" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "class_uid" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "time" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "severity_id" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "type_uid" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "metadata" : <document></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "actor" : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "user" : {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "type_id" : <int>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "name" : <string>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "groups" : <array of documents></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-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">
activity_id
</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>
Activity type. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ocsf-type-mapping" target="_self">
<span>
OCSF Type Mapping
<!-- -->
.
</span>
</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">
category_uid
</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>
Audit event category. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ocsf-category-mapping" target="_self">
<span>
OCSF Category Mapping
<!-- -->
.
</span>
</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">
class_uid
</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>
Audit event class. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ocsf-class-mapping" target="_self">
<span>
OCSF Class Mapping
<!-- -->
.
</span>
</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">
time
</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 milliseconds after the Unix epoch that the event
occurred.
</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">
severity_id
</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>
Severity of the audited event.
</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">
type_uid
</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>
Combination of the audited event's class, activity, and category.
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-ocsf-type-mapping" target="_self">
<span>
OCSF Type Mapping
<!-- -->
.
</span>
</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">
metadata
</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>
Metadata about the event such as product and schema version.
</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">
actor
</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>
Information about the user who performed the action.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
Log messages may contain additional fields depending on the event
that was logged.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-ocsf-category-mapping">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
OCSF Category Mapping
<a class="headerlink leafygreen-ui-1kepx47" href="#ocsf-category-mapping" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ocsf-category-mapping">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
This table describes the
<code class="leafygreen-ui-1l06pbn">
category_uid
</code>
values:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<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>
<code class="leafygreen-ui-1l06pbn">
category_uid
</code>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Category
</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">
1
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
System Activity
</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">
2
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Findings
</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">
3
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-vm4wms" tabindex="0">
IAM
</span>
</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">
4
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Network Activity
</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">
5
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Discovery
</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">
6
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Application Activity
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-ocsf-class-mapping">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
OCSF Class Mapping
<a class="headerlink leafygreen-ui-1kepx47" href="#ocsf-class-mapping" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ocsf-class-mapping">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For a complete list of
<span class="leafygreen-ui-vm4wms" tabindex="0">
OCSF
</span>
<code class="leafygreen-ui-1l06pbn">
class_uids
</code>
and how they map to
different classes, see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://schema.ocsf.io/1.2.0/classes" rel="noopener noreferrer">
<span>
OCSF 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>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-ocsf-type-mapping">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
OCSF Type Mapping
<a class="headerlink leafygreen-ui-1kepx47" href="#ocsf-type-mapping" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="ocsf-type-mapping">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
type_uid
</code>
field represents a combination of the audited event's
class, activity, and category. The resulting UUID indicates the type of
activity that occurred.
</p>
<p class="leafygreen-ui-1kp3ins">
Specifically,
<code class="leafygreen-ui-1l06pbn">
type_uid
</code>
is
<code class="leafygreen-ui-1l06pbn">
( class_uid * 100 ) + (activity_id)
</code>
,
with
<code class="leafygreen-ui-1l06pbn">
category_id
</code>
being the thousands place in a
<code class="leafygreen-ui-1l06pbn">
class_id
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
This table describes how audited actions map to
<code class="leafygreen-ui-1l06pbn">
type_uid
</code>
:
</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:10%"/>
<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>
Action Type
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
type_uid
</code>
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Category
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Class
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Activity
</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">
addShard
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500101
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
applicationMessage
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
100799
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
System
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Process Activity
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Other
</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">
auditConfigure
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
or
<code class="leafygreen-ui-1l06pbn">
500203
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Discovery
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
is Create
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
3
</code>
is Update
</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">
authzCheck
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
600301
</code>
-
<code class="leafygreen-ui-1l06pbn">
600304
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Application
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
API Activity
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
1
</code>
is Create
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
2
</code>
is Read
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
3
</code>
is Update
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
4
</code>
is Delete
</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">
authenticate
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Authentication
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Logon
</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">
clientMetadata
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
400101
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Network
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Network Activity
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Open
</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">
createCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300401
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
createDatabase
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300401
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
createIndex
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300401
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
createRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300101
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
createUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300101
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
directAuthMutation
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300100
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Unknown
</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">
dropAllRolesFromDatabase
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300106
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropAllUsersFromDatabase
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300106
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300404
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropDatabase
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300404
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropIndex
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300404
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropPrivilegesToRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300107
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Attach Policy
</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">
dropRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300106
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
dropUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300106
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Delete
</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">
enableSharding
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
getClusterParameter
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
600302
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Application
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
API Activity
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Read
</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">
grantRolesToRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300107
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Attach Policy
</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">
grantRolesToUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300107
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Attach Policy
</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">
importCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300401
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Create
</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">
logout
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300202
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Authentication
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Logoff
</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">
refineCollectionShardKey
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
removeShard
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
renameCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300403
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Entity Management
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Update
</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">
replSetReconfig
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
revokePrivilegesFromRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300108
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Detach Policy
</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">
revokeRolesFromRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300108
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Detach Policy
</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">
revokeRolesFromUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300108
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Detach Policy
</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">
rotateLog
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
100799
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
System
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Process
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Other
</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">
setClusterParameter
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
shardCollection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
shutdown
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
100702
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
System
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Process
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Terminate
</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">
startup
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
100701
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
System
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Process
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Launch
</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">
updateCachedClusterServerParameter
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
500201
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configuration
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Device Config State
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Log
</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">
updateRole
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300199
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Other
</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">
updateUser
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
300199
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
IAM
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Account Change
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Other
</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">
The following examples show
<span class="leafygreen-ui-vm4wms" tabindex="0">
OCSF
</span>
schema log messages for different
action types.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Authenticate Action
<a class="headerlink leafygreen-ui-1kepx47" href="#authenticate-action" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="authenticate-action">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"activity_id\" : 1,\n \"category_uid\" : 3,\n \"class_uid\" : 3002,\n \"time\" : 1710715316123,\n \"severity_id\" : 1,\n \"type_uid\" : 300201,\n \"metadata\" : {\n \"correlation_uid\" : \"20ec4769-984d-445c-aea7-da0429da9122\",\n \"product\" : \"MongoDB Server\",\n \"version\" : \"1.0.0\"\n },\n \"actor\" : {\n \"user\" : {\n \"type_id\" : 1,\n \"name\" : \"admin.admin\",\n \"groups\" : [ { \"name\" : \"admin.root\" } ]\n }\n },\n \"src_endpoint\" : { \"ip\" : \"127.0.0.1\", \"port\" : 56692 },\n \"dst_endpoint\" : { \"ip\" : \"127.0.0.1\", \"port\" : 20040 },\n \"user\" : { \"type_id\" : 1, \"name\" : \"admin.admin\" },\n \"auth_protocol\" : \"SCRAM-SHA-256\",\n \"unmapped\" : { \"atype\" : \"authenticate\" }\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-string">"activity_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"category_uid"</span> <!-- -->: <span class="lg-highlight-number">3</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_uid"</span> <!-- -->: <span class="lg-highlight-number">3002</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"time"</span> <!-- -->: <span class="lg-highlight-number">1710715316123</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"severity_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type_uid"</span> <!-- -->: <span class="lg-highlight-number">300201</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"correlation_uid"</span> <!-- -->: <span class="lg-highlight-string">"20ec4769-984d-445c-aea7-da0429da9122"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product"</span> <!-- -->: <span class="lg-highlight-string">"MongoDB Server"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"1.0.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">"actor"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"user"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type_id"</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">"admin.admin"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"groups"</span> <!-- -->: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"admin.root"</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">"src_endpoint"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"ip"</span> <!-- -->: <span class="lg-highlight-string">"127.0.0.1"</span>, <span class="lg-highlight-string">"port"</span> <!-- -->: <span class="lg-highlight-number">56692</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dst_endpoint"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"ip"</span> <!-- -->: <span class="lg-highlight-string">"127.0.0.1"</span>, <span class="lg-highlight-string">"port"</span> <!-- -->: <span class="lg-highlight-number">20040</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"user"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"type_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"admin.admin"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"auth_protocol"</span> <!-- -->: <span class="lg-highlight-string">"SCRAM-SHA-256"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"unmapped"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"atype"</span> <!-- -->: <span class="lg-highlight-string">"authenticate"</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">
AuthCheck Action
<a class="headerlink leafygreen-ui-1kepx47" href="#authcheck-action" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="authcheck-action">
</div>
</a>
</h3>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"activity_id\" : 0,\n \"category_uid\" : 6,\n \"class_uid\" : 6003,\n \"time\" : 1710715315002,\n \"severity_id\" : 1,\n \"type_uid\" : 600300,\n \"metadata\" : {\n \"correlation_uid\" : \"af4510fb-0a9f-49aa-b988-06259a7a861d\",\n \"product\" : \"MongoDB Server\",\n \"version\" : \"1.0.0\"\n },\n \"actor\" : {},\n \"src_endpoint\" : { \"ip\" : \"127.0.0.1\", \"port\" : 45836 },\n \"dst_endpoint\" : { \"ip\" : \"127.0.0.1\", \"port\" : 20040 },\n \"api\" : {\n \"operation\" : \"getParameter\",\n \"request\" : { \"uid\" : \"admin\" },\n \"response\" : { \"code\" : 13, \"error\" : \"Unauthorized\" }\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-string">"activity_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"category_uid"</span> <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"class_uid"</span> <!-- -->: <span class="lg-highlight-number">6003</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"time"</span> <!-- -->: <span class="lg-highlight-number">1710715315002</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"severity_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"type_uid"</span> <!-- -->: <span class="lg-highlight-number">600300</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metadata"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"correlation_uid"</span> <!-- -->: <span class="lg-highlight-string">"af4510fb-0a9f-49aa-b988-06259a7a861d"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"product"</span> <!-- -->: <span class="lg-highlight-string">"MongoDB Server"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"version"</span> <!-- -->: <span class="lg-highlight-string">"1.0.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">"actor"</span> <!-- -->: <!-- -->{<!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"src_endpoint"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"ip"</span> <!-- -->: <span class="lg-highlight-string">"127.0.0.1"</span>, <span class="lg-highlight-string">"port"</span> <!-- -->: <span class="lg-highlight-number">45836</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dst_endpoint"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"ip"</span> <!-- -->: <span class="lg-highlight-string">"127.0.0.1"</span>, <span class="lg-highlight-string">"port"</span> <!-- -->: <span class="lg-highlight-number">20040</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"api"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"operation"</span> <!-- -->: <span class="lg-highlight-string">"getParameter"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"request"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uid"</span> <!-- -->: <span class="lg-highlight-string">"admin"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"response"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"code"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"error"</span> <!-- -->: <span class="lg-highlight-string">"Unauthorized"</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>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/KeyVault.createKey/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
KeyVault.createKey()
<a class="headerlink leafygreen-ui-1kepx47" href="#keyvault.createkey--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.createkey--">
</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.createKey(keyManagementService, customerMasterKey, ["keyAltName"])
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-KeyVault.createKey" 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.createKey">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a data encryption key to the key vault associated to the
database connection.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/csfle/#std-label-manual-csfle-feature">
Client-Side Field Level Encryption
</a>
uses data encryption keys for supporting
encryption and decryption of field values.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createKey()
</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.createKey(\n keyManagementService,\n customerMasterKey,\n [ \"keyAltName\" ]\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">keyVault <!-- -->= <!-- -->db.<span class="lg-highlight-title lg-highlight-function">getMongo</span>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">getKeyVault</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">keyVault.<span class="lg-highlight-title lg-highlight-function">createKey</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->keyManagementService<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->customerMasterKey<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <span class="lg-highlight-string">"keyAltName"</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>
<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">
keyManagementService
</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">
<em>
Required
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/fundamentals/kms-providers/#std-label-qe-fundamentals-kms-providers">
Key Management Service (KMS)
</a>
to use for retrieving the
Customer Master Key (CMK). Accepts the following parameters:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
aws
</code>
for
<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>
. Requires specifying a
Customer Master Key (CMK) string for
<code class="leafygreen-ui-1l06pbn">
customerMasterKey
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
azure
</code>
for
<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>
. Requires
specifying a Customer Master Key (CMK) document for
<code class="leafygreen-ui-1l06pbn">
customerMasterKey
</code>
.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
gcp
</code>
for
<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>
. Requires specifying a
Customer Master Key (CMK) document for
<code class="leafygreen-ui-1l06pbn">
customerMasterKey
</code>
.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
local
</code>
for a
<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">
If the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#mongodb-method-Mongo">
<code class="leafygreen-ui-1l06pbn">
database connection
</code>
</a>
was not
configured with the specified KMS, data encryption key
creation fails.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
customerMasterKey
</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">
The Customer Master Key (CMK) to use for encrypting the data
encryption key. Required if
<code class="leafygreen-ui-1l06pbn">
keyManagementService
</code>
is
<code class="leafygreen-ui-1l06pbn">
aws
</code>
,
<code class="leafygreen-ui-1l06pbn">
azure
</code>
, or
<code class="leafygreen-ui-1l06pbn">
gcp
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Provide the CMK as follows depending on your KMS provider:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For 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>
, specify the full
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html" rel="noopener noreferrer">
<span>
Amazon Resource Name (ARN)
</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 the master key as a single string.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the
<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>
KMS, specify a
document containing the following key value pairs:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyName
</code>
- The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.microsoft.com/en-us/azure/key-vault/general/about-keys-secrets-certificates#vault-name-and-object-name" rel="noopener noreferrer">
<span>
Azure Key Vault Name
</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyVaultEndpoint
</code>
- The DNS name of the Azure Key Vault
to use
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyVersion
</code>
- Optional. The version of the key
specified in
<code class="leafygreen-ui-1l06pbn">
keyName
</code>
, if applicable
</p>
</li>
</ul>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the
<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>
, specify a
document containing the following key value pairs:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
projectId
</code>
- The GCP project name
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
location
</code>
- The location of the KMS keyring
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyRing
</code>
- The name of the KMS keyring (often 'global')
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyName
</code>
- The name of the key to use
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyVersion
</code>
- Optional. The version of the key
specified in
<code class="leafygreen-ui-1l06pbn">
keyName
</code>
, if applicable
</p>
</li>
</ul>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createKey()
</code>
</span>
</a>
requests
that the KMS encrypt the data encryption key material
using the specified CMK. If the CMK does not exist
<em>
or
</em>
if the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/Mongo/#std-label-autoEncryptionOpts">
<code class="leafygreen-ui-1l06pbn">
AutoEncryptionOpts
</code>
</a>
configuration
does not have sufficient privileges to use the CMK,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createKey()
</code>
</span>
</a>
returns an error.
</p>
<p class="leafygreen-ui-1kp3ins">
This parameter has no effect if
<code class="leafygreen-ui-1l06pbn">
keyManagementService
</code>
is
<code class="leafygreen-ui-1l06pbn">
local
</code>
and can be safely omitted.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
keyAltName
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
array of strings
</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">
The alternative name for the data encryption key. Use
<code class="leafygreen-ui-1l06pbn">
keyAltName
</code>
to improve findability of a specific data
encryption key, or as an analog to a comment.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
method automatically creates a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
on the
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
field with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/#std-label-index-type-partial">
partial index
</a>
filter for only documents where
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
exists.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
options
</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">
<em>
Optional
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
A document that specifies options for the new key.
<code class="leafygreen-ui-1l06pbn">
options
</code>
has the following fields:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
masterKey
</code>
: the new master key to encrypt data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
: an array of alternate names, one per
master key.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyMaterial
</code>
: bindata used to create the key.
</p>
</li>
</ul>
</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>
The
<code class="leafygreen-ui-1l06pbn">
UUID
</code>
unique identifier of the created data encryption
key.
</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 is intended for rapid evaluation of
client-side field level encryption. For specific examples of using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
KeyVault.createKey()
</code>
</span>
</a>
with each supported
<span class="leafygreen-ui-vm4wms" tabindex="0">
KMS
</span>
provider, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/quick-start/#std-label-qe-field-level-encryption-data-key-create">
Create a Data Key
<!-- -->
.
</a>
</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.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
KeyVault.createKey()
</code>
</span>
</a>
method to
create a new data encryption key using the locally managed key:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"keyVault = encryptedClient.getKeyVault()\nkeyVault.createKey(\"local\", [\"data-encryption-key\"])","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">keyVault <!-- -->= <!-- -->encryptedClient.<span class="lg-highlight-title lg-highlight-function">getKeyVault</span>(<!-- -->)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">keyVault.<span class="lg-highlight-title lg-highlight-function">createKey</span>(<span class="lg-highlight-string">"local"</span>, <!-- -->[<span class="lg-highlight-string">"data-encryption-key"</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 successful,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-KeyVault.createKey" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
createKey()
</code>
</span>
</a>
returns the
<code class="leafygreen-ui-1l06pbn">
UUID
</code>
of
the new data encryption key. To retrieve the new data encryption
key document from the key vault, either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.getKey/#mongodb-method-KeyVault.getKey">
<code class="leafygreen-ui-1l06pbn">
getKey()
</code>
</a>
to retrieve the created key by
<code class="leafygreen-ui-1l06pbn">
UUID
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
-or-
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.getKeyByAltName/#mongodb-method-KeyVault.getKeyByAltName">
<code class="leafygreen-ui-1l06pbn">
getKeyByAltName()
</code>
</a>
to retrieve the key by its
alternate name.
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.collection.storageSize/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.collection.storageSize()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.storagesize--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.collection.storagesize--">
</div>
</a>
</h1>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.collection.storageSize()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.storageSize" 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.collection.storageSize">
</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 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/collStats/#mongodb-data-collStats.storageSize">
<code class="leafygreen-ui-1l06pbn">
storageSize
</code>
</a>
field returned
by 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">
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 total amount of storage in bytes allocated to this
collection for document storage.
<p class="leafygreen-ui-1kp3ins">
If collection data is compressed (which is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--wiredTigerCollectionBlockCompressor">
<code class="leafygreen-ui-1l06pbn">
default for WiredTiger
</code>
</a>
), the storage size
reflects the compressed size and may be smaller than the
value returned by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dataSize/#mongodb-method-db.collection.dataSize">
<code class="leafygreen-ui-1l06pbn">
db.collection.dataSize()
</code>
.
</a>
</p>
</td>
</tr>
</tbody>
</table>
<p class="leafygreen-ui-1kp3ins">
To run on a replica set member,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
</a>
operations require the member
to be in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state. If the member
is in another state, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
<code class="leafygreen-ui-1l06pbn">
STARTUP2
</code>
</a>
, the
operation errors.
</p>
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/reference/collation/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Collation
<a class="headerlink leafygreen-ui-1kepx47" href="#collation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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">
</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="#collation-document" target="_self">
<span>
Collation Document
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#operations-that-support-collation" target="_self">
<span>
Operations that Support Collation
</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="#restrictions" target="_self">
<span>
Restrictions
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
Collation allows users to specify language-specific rules for string
comparison, such as rules for lettercase and accent marks.
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify collation for a collection or a view, an index, or
specific operations that support collation.
</p>
<p class="leafygreen-ui-1kp3ins">
To specify collation when you query documents in the MongoDB Atlas UI, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/documents/#specify-collation" target="_self">
<span>
Specify Collation
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-document-fields">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Collation Document
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-document" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-document">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
A collation document has the following fields:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\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-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"> 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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation-document-fields" target="_self">
<span>
Collation Document
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Default collation parameter values vary depending on which
locale you specify. For a complete list of default collation
parameters and the locales they are associated with, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation-locales-defaults/#std-label-collation-default-params">
Collation Default Parameters
<!-- -->
.
</a>
</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: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">
locale
</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 ICU locale. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation-locales-defaults/#std-label-collation-languages-locales">
Supported Languages and Locales
</a>
for a
list of supported locales.
</p>
<p class="leafygreen-ui-1kp3ins">
To specify simple binary comparison, specify
<code class="leafygreen-ui-1l06pbn">
locale
</code>
value of
<code class="leafygreen-ui-1l06pbn">
"simple"
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
strength
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-parameter-strength">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. The level of comparison to perform.
Corresponds to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/collation/concepts.html#comparison-levels" rel="noopener noreferrer">
<span>
ICU Comparison Levels
</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>
.
Possible values are:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<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>
Value
</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>
1
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Primary level of comparison. Collation performs
comparisons of the base characters only, ignoring other
differences such as diacritics and case.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
2
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Secondary level of comparison. Collation performs comparisons
up to secondary differences, such as diacritics.
That is, collation performs comparisons of base characters
(primary differences) and diacritics (secondary differences).
Differences between base characters takes precedence over
secondary differences.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
3
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Tertiary level of comparison. Collation performs comparisons
up to tertiary differences, such as case and letter variants.
That is, collation performs comparisons of base characters
(primary differences), diacritics (secondary differences), and
case and variants (tertiary differences). Differences between
base characters takes precedence over secondary differences,
which takes precedence over tertiary differences.
</p>
<p class="leafygreen-ui-1kp3ins">
This is the default level.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
4
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Quaternary Level. Limited for specific use case to
consider punctuation when levels 1-3 ignore punctuation
or for processing Japanese text.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
5
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Identical Level. Limited for specific use case of tie
breaker.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/collation/concepts.html#comparison-levels" rel="noopener noreferrer">
<span>
ICU Collation: Comparison Levels
</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 details.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
caseLevel
</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. Flag that determines whether to include case comparison
at
<code class="leafygreen-ui-1l06pbn">
strength
</code>
level
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
2
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, include case comparison:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When used with
<code class="leafygreen-ui-1l06pbn">
strength:1
</code>
, collation compares base characters
and case.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When used with
<code class="leafygreen-ui-1l06pbn">
strength:2
</code>
, collation compares base characters,
diacritics (and possible other secondary differences) and case.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, do not include case comparison at level
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
2
</code>
. The default is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/collation/concepts.html#caselevel" rel="noopener noreferrer">
<span>
ICU Collation: Case Level
</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>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
caseFirst
</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">
Optional. A field that determines sort order of case differences during
tertiary level comparisons.
</p>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<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>
Value
</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">
"upper"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Uppercase sorts before lowercase.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"lower"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lowercase sorts before uppercase.
</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>
Default value. Similar to
<code class="leafygreen-ui-1l06pbn">
"lower"
</code>
with slight
differences. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/strings/properties.html#customization" rel="noopener noreferrer">
<span>
https://unicode-org.github.io/icu/userguide/strings/properties.html#customization
</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 details of differences.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
numericOrdering
</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. Flag that determines whether to compare numeric strings as numbers
or as strings.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, compare as numbers. For example,
<code class="leafygreen-ui-1l06pbn">
"10"
</code>
is greater than
<code class="leafygreen-ui-1l06pbn">
"2"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, compare as strings. For example,
<code class="leafygreen-ui-1l06pbn">
"10"
</code>
is less than
<code class="leafygreen-ui-1l06pbn">
"2"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Default is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-numeric-order-restrictions" target="_self">
<span>
numericOrdering Restrictions
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
alternate
</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">
Optional. Field that determines whether collation should consider whitespace
and punctuation as base characters for purposes of comparison.
</p>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<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>
Value
</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">
"non-ignorable"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Whitespace and punctuation are considered base characters.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"shifted"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Whitespace and punctuation are not considered base characters
and are only distinguished at strength levels greater than 3.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/collation/concepts.html#comparison-levels" rel="noopener noreferrer">
<span>
ICU Collation: Comparison Levels
</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 more information.
</p>
<p class="leafygreen-ui-1kp3ins">
Default is
<code class="leafygreen-ui-1l06pbn">
"non-ignorable"
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
maxVariable
</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">
Optional. Field that determines up to which characters are considered
ignorable when
<code class="leafygreen-ui-1l06pbn">
alternate: "shifted"
</code>
. Has no effect if
<code class="leafygreen-ui-1l06pbn">
alternate: "non-ignorable"
</code>
</p>
<p class="leafygreen-ui-1kp3ins">
Possible values are:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<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>
Value
</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">
"punct"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Both whitespace and punctuation are ignorable and not
considered base characters.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"space"
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Whitespace is ignorable and not considered to be base
characters.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
backwards
</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. Flag that determines whether strings with diacritics sort from back
of the string, such as with some French dictionary ordering.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, compare from back to front.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, compare from front to back.
</p>
<p class="leafygreen-ui-1kp3ins">
The default value is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
normalization
</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. Flag that determines whether to check if text require normalization
and to perform normalization. Generally, majority of text does not
require this normalization processing.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
true
</code>
, check if fully normalized and perform normalization to
compare text.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, does not check.
</p>
<p class="leafygreen-ui-1kp3ins">
The default value is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/collation/concepts.html#normalization" rel="noopener noreferrer">
<span>
https://unicode-org.github.io/icu/userguide/collation/concepts.html#normalization
</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 details.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Operations that Support Collation
<a class="headerlink leafygreen-ui-1kepx47" href="#operations-that-support-collation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-collation">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can specify collation for the following operations:
</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 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>
<div class="header-buffer" id="ref-index-restriction-id1">
</div>
<div class="header-buffer" id="ref-index-restriction-id2">
</div>
<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>
Commands
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
Methods
</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/create/#mongodb-dbcommand-dbcmd.create">
<code class="leafygreen-ui-1l06pbn">
create
</code>
</a>
</div>
</div>
</td>
<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/method/db.createCollection/#mongodb-method-db.createCollection">
<code class="leafygreen-ui-1l06pbn">
db.createCollection()
</code>
</a>
</div>
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.createView/#mongodb-method-db.createView">
<code class="leafygreen-ui-1l06pbn">
db.createView()
</code>
</a>
</div>
</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/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes">
<code class="leafygreen-ui-1l06pbn">
createIndexes
</code>
</a>
<a class="footnote-reference header-buffer" href="#footnote-index-restriction" id="ref-index-restriction-id1">
[
<!-- -->
1
<!-- -->
]
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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>
<a class="footnote-reference header-buffer" href="#footnote-index-restriction" id="ref-index-restriction-id2">
[
<!-- -->
1
<!-- -->
]
</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/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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>
</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>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.distinct/#mongodb-method-db.collection.distinct">
<code class="leafygreen-ui-1l06pbn">
db.collection.distinct()
</code>
</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/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify">
<code class="leafygreen-ui-1l06pbn">
findAndModify
</code>
</a>
</div>
</div>
</td>
<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/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>
</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>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.collation/#mongodb-method-cursor.collation">
<code class="leafygreen-ui-1l06pbn">
cursor.collation()
</code>
</a>
to specify collation for
<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>
</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/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.mapReduce/#mongodb-method-db.collection.mapReduce">
<code class="leafygreen-ui-1l06pbn">
db.collection.mapReduce()
</code>
</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/command/delete/#mongodb-dbcommand-dbcmd.delete">
<code class="leafygreen-ui-1l06pbn">
delete
</code>
</a>
</div>
</div>
</td>
<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/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>
</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/update/#mongodb-dbcommand-dbcmd.update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
</div>
</div>
</td>
<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/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>
</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/shardCollection/#mongodb-dbcommand-dbcmd.shardCollection">
<code class="leafygreen-ui-1l06pbn">
shardCollection
</code>
</a>
</div>
</div>
</td>
<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/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
</div>
</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/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 class="line-block">
<div class="line">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.count/#mongodb-method-db.collection.count">
<code class="leafygreen-ui-1l06pbn">
db.collection.count()
</code>
</a>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<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>
Individual update, replace, and delete operations in
<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>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-index-restriction" 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-index-restriction-id1">
1
</a>
,
<a href="#ref-index-restriction-id2">
2
</a>
)
</em>
<!-- -->
Some index types do not support collation. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation-unsupported-index-types" target="_self">
<span>
Collation and Unsupported Index Types
</span>
</a>
for details.
</td>
</tr>
</tbody>
</table>
</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">
Local Variants
<a class="headerlink leafygreen-ui-1kepx47" href="#local-variants" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-variants">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Some collation locales have variants, which employ special
language-specific rules. To specify a locale variant, use the following
syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"locale\" : \"<locale>@collation=<variant>\" }","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">"locale"</span> <!-- -->: <span class="lg-highlight-string">"<locale code>@collation=<variant>"</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 example, to use the
<code class="leafygreen-ui-1l06pbn">
unihan
</code>
variant of the Chinese collation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"locale\" : \"zh@collation=unihan\" }","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">"locale"</span> <!-- -->: <span class="lg-highlight-string">"zh@collation=unihan"</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 complete list of all collation locales and their variants, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation-locales-defaults/#std-label-collation-languages-locales">
Collation Locales
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-ref-collation-and-views">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Collation and Views
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-and-views" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-views">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can specify a default
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation" target="_self">
<span>
collation
</span>
</a>
for a view at creation time. If no collation is specified, the
view's default collation is the "simple" binary comparison
collator. That is, the view does not inherit the collection's
default collation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
String comparisons on the view use the view's default collation.
An operation that attempts to change or override a view's default
collation will fail with an error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If creating a view from another view, you cannot specify a
collation that differs from the source view's collation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If performing an aggregation that involves multiple views, such as
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/graphLookup/#mongodb-pipeline-pipe.-graphLookup">
<code class="leafygreen-ui-1l06pbn">
$graphLookup
</code>
</a>
, the views must
have the same
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation" target="_self">
<span>
collation
<!-- -->
.
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-index-use">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Collation and Index Use
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-and-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="collation-and-index-use">
</div>
</a>
</h3>
<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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation-parameter-strength" target="_self">
<span>
strength
</span>
</a>
parameter.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-unsupported-index-types">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Collation and Unsupported Index Types
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-and-unsupported-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-unsupported-index-types">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The following indexes only support simple binary comparison and do
not support
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-collation" target="_self">
<span>
collation
<!-- -->
:
</span>
</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>
</section>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" 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>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-numeric-order-restrictions">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
numericOrdering
<a class="headerlink leafygreen-ui-1kepx47" href="#numericordering" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="numericordering">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When specifying the
<code class="leafygreen-ui-1l06pbn">
numericOrdering
</code>
as
<code class="leafygreen-ui-1l06pbn">
true
</code>
the following
restrictions apply:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Only contiguous non-negative integer substrings of digits are
considered in the comparisons.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
numericOrdering
</code>
does not support:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
+
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
-
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
decimal separators, like decimal points and decimal commas
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
exponents
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Only Unicode code points in the Number or Decimal Digit (Nd) category
are treated as digits.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If a digit length exceeds 254 characters, the excess characters are
treated as a separate number.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Consider a collection with the following string number and decimal
values:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.c.insertMany(\n [\n { \"n\" : \"1\" },\n { \"n\" : \"2\" },\n { \"n\" : \"2.1\" },\n { \"n\" : \"-2.1\" },\n { \"n\" : \"2.2\" },\n { \"n\" : \"2.10\" },\n { \"n\" : \"2.20\" },\n { \"n\" : \"-10\" },\n { \"n\" : \"10\" },\n { \"n\" : \"20\" },\n { \"n\" : \"20.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">c</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">"n"</span> <!-- -->: <span class="lg-highlight-string">"1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"2"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"2.1"</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"-2.1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"2.2"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"2.10"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"2.20"</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"-10"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"10"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"20"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"n"</span> <!-- -->: <span class="lg-highlight-string">"20.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 following
<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>
query uses a
collation document containing the
<code class="leafygreen-ui-1l06pbn">
numericOrdering
</code>
parameter:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.c.find(\n { }, { _id: 0 }\n).sort(\n { n: 1 }\n).collation( {\n locale: 'en_US',\n numericOrdering: 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">c</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">_id</span>: <span class="lg-highlight-number">0</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-function">sort</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">).<span class="lg-highlight-title lg-highlight-function">collation</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">locale</span>: <span class="lg-highlight-string">'en_US'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">numericOrdering</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 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 { n: '-2.1' },\n { n: '-10' },\n { n: '1' },\n { n: '2' },\n { n: '2.1' },\n { n: '2.2' },\n { n: '2.10' },\n { n: '2.20' },\n { n: '10' },\n { n: '20' },\n { n: '20.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="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'-2.1'</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'-10'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'1'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'2'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'2.1'</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'2.2'</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'2.10'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'2.20'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'10'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'20'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">n</span>: <span class="lg-highlight-string">'20.1'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
numericOrdering: true
</code>
sorts the string values in ascending
order as if they were numeric values.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The two negative values
<code class="leafygreen-ui-1l06pbn">
-2.1
</code>
and
<code class="leafygreen-ui-1l06pbn">
-10
</code>
are not sorted in the
expected sort order because they have unsupported
<code class="leafygreen-ui-1l06pbn">
-
</code>
characters.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The value
<code class="leafygreen-ui-1l06pbn">
2.2
</code>
is sorted before the value
<code class="leafygreen-ui-1l06pbn">
2.10
</code>
, due to the fact
that the
<code class="leafygreen-ui-1l06pbn">
numericOrdering
</code>
parameter does not support decimal
values.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
As a result,
<code class="leafygreen-ui-1l06pbn">
2.2
</code>
and
<code class="leafygreen-ui-1l06pbn">
2.10
</code>
are sorted in lexicographic order.
</p>
</li>
</ul>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/collation-locales-defaults/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Collation Locales and Default Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-locales-and-default-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="collation-locales-and-default-parameters">
</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="#supported-languages-and-locales" target="_self">
<span>
Supported Languages and Locales
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#collation-default-parameters" target="_self">
<span>
Collation Default Parameters
</span>
</a>
</li>
</ul>
</div>
<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>
<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">
Some collation locales have variants, which employ special
language-specific rules. To specify a locale variant, use the following
syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"locale\" : \"<locale>@collation=<variant>\" }","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">"locale"</span> <!-- -->: <span class="lg-highlight-string">"<locale code>@collation=<variant>"</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 example, to use the
<code class="leafygreen-ui-1l06pbn">
unihan
</code>
variant of the Chinese collation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"locale\" : \"zh@collation=unihan\" }","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">"locale"</span> <!-- -->: <span class="lg-highlight-string">"zh@collation=unihan"</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 the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation page
</a>
for a full description of
collation behavior and syntax.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-languages-locales">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Supported Languages and Locales
<a class="headerlink leafygreen-ui-1kepx47" href="#supported-languages-and-locales" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="supported-languages-and-locales">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB's collation feature supports the following languages. The
following table lists the supported languages and the associated
locales as defined by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://unicode-org.github.io/icu/userguide/locale/#locale" rel="noopener noreferrer">
<span>
ICU Locale
ID
</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>
.
<a class="footnote-reference header-buffer" href="#footnote-missing-locale" id="ref-missing-locale-id1">
[
<!-- -->
1
<!-- -->
]
</a>
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<thead class="leafygreen-ui-a9ho40">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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>
Language
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Locale
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Variants
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Afrikaans
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
af
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Albanian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sq
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Amharic
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
am
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Arabic
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ar
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
compat
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Armenian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hy
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Assamese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
as
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Azeri
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
az
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Bengali
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Belarusian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
be
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Bengali
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
traditional
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Bosnian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bs
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Bosnian (Cyrillic)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bs_Cyrl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Bulgarian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bg
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Burmese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
my
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Catalan
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ca
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Cherokee
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
chr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Chinese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zh
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
big5han
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
gb2312han
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
unihan
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
zhuyin
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Chinese (Traditional)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zh_Hant
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Croatian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Czech
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
cs
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Danish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
da
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Dutch
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
nl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Dzongkha
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dz
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
English
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
en
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
English (United States)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
en_US
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
English (United States, Computer)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
en_US_POSIX
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Esperanto
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
eo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Estonian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
et
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Ewe
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ee
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Faroese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Filipino
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fil
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Finnish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fi
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
traditional
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
French
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
French (Canada)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fr_CA
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Galician
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
gl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Georgian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ka
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
German
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
de
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
eor
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
phonebook
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
German (Austria)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
de_AT
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
phonebook
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Greek
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
el
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Gujarati
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
gu
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hausa
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ha
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hawaiian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
haw
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hebrew
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
he
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hindi
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hi
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hungarian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hu
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Icelandic
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
is
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Igbo
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ig
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Inari Sami
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
smn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Indonesian
</div>
</div>
</td>
<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>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Irish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ga
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Italian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
it
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Japanese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ja
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
unihan
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<thead class="leafygreen-ui-a9ho40">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Language
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Locale
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Variants
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kalaallisut
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
kl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kannada
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
kn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
traditional
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kazakh
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
kk
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Khmer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
km
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Konkani
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
kok
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Korean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ko
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
searchjl
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
unihan
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Kyrgyz
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ky
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lakota
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lkt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lao
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Latvian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lv
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lingala
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ln
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
phonetic
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lithuanian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Lower Sorbian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dsb
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Luxembourgish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
lb
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Macedonian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mk
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Malay
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ms
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Malayalam
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ml
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Maltese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Marathi
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Mongolian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
mn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Nepali
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ne
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Northern Sami
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
se
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Norwegian Bokmål
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
nb
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Norwegian Nynorsk
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
nn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Oriya
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
or
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Oromo
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
om
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Pashto
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ps
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Persian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fa
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Persian (Afghanistan)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
fa_AF
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Polish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
pl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Portuguese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
pt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Punjabi
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
pa
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Romanian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ro
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Russian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ru
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Serbian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Serbian (Latin)
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sr_Latn
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Sinhala
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
si
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
dictionary
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Slovak
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sk
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Slovenian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sl
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Spanish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
es
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
traditional
</code>
</div>
</div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Swahili
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sw
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Swedish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
sv
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Tamil
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ta
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Telugu
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
te
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Thai
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
th
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Tibetan
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Tongan
</div>
</div>
</td>
<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>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Turkish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
tr
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Ukrainian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
uk
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Upper Sorbian
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
hsb
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Urdu
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ur
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Uyghur
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
ug
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Vietnamese
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
vi
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
traditional
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Walser
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
wae
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Welsh
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
cy
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Yiddish
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
yi
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
search
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Yoruba
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
yo
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Zulu
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zu
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
To explicitly specify simple binary comparison, specify
<code class="leafygreen-ui-1l06pbn">
locale
</code>
value of
<code class="leafygreen-ui-1l06pbn">
"simple"
</code>
.
</p>
</div>
</div>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-missing-locale" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-missing-locale-id1">
1
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
<!-- -->
To request support for a locale, please file a JIRA ticket with the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://jira.mongodb.org/browse/SERVER" rel="noopener noreferrer">
<span>
Server project
</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>
</td>
</tr>
</tbody>
</table>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collation-default-params">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Collation Default Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#collation-default-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="collation-default-parameters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
A collation document contains several
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation-document-fields">
optional parameters
</a>
in
addition to the required
<code class="leafygreen-ui-1l06pbn">
locale
</code>
parameter. Depending on which
<code class="leafygreen-ui-1l06pbn">
locale
</code>
you use, the default parameters may be different.
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation page
</a>
for a
full description of collation syntax.
</p>
<p class="leafygreen-ui-1kp3ins">
The following default parameters are consistent across all locales:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
caseLevel : false
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
strength : 3
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
numericOrdering : false
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
maxVariable : punct
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The following table shows the default collation parameters which may
vary across different locales:
</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>
Locale
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
caseFirst
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
alternate
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
normalization
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
backwards
</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">
af
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sq
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
am
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ar
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ar@collation=compat
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hy
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
as
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
az
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
az@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
be
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bn@collation=traditional
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bs
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bs@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bs_Cyrl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
bg
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
my
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ca
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ca@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
chr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh@collation=big5han
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh@collation=gb2312han
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh@collation=unihan
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh@collation=zhuyin
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zh_Hant
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hr@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
cs
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
cs@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
da
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
upper
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
da@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
nl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
dz
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
en
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
en_US_POSIX
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
en_US
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
eo
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
et
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ee
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fo
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fo@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fil
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fi
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fi@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fi@collation=traditional
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fr_CA
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
TRUE
</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">
gl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
gl@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ka
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de@collation=phonebook
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de@collation=eor
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de_AT
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
de_AT@collation=phonebook
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
el
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
gu
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ha
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
haw
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
he
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
he@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hi
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hu
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
is
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
is@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ig
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
smn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
smn@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
id
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ga
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
it
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ja
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ja@collation=unihan
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kl@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kn@collation=traditional
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kk
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
km
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
kok
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ko
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ko@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ko@collation=searchjl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ko@collation=unihan
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ky
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
lkt
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
lo
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
lv
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ln
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ln@collation=phonetic
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
lt
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
dsb
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
lb
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
mk
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ms
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ml
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
mt
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
upper
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
mr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
mn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ne
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
se
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
se@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
nb
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
nb@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
nn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
nn@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
or
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
om
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ps
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fa
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
fa_AF
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
pl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
pt
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
pa
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ro
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ru
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sr_Latn
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sr_Latn@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
si
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
si@collation=dictionary
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sk
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sk@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sl
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
es
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
es@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
es@collation=traditional
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sw
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sv
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
sv@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ta
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
te
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
th
</code>
</div>
</div>
</td>
<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>
shifted
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
TRUE
</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>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
bo
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
to
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
tr
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
tr@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
uk
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
hsb
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ur
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
ug
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
vi
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
vi@collation=traditional
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
wae
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
cy
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
yi
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
yi@collation=search
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
yo
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<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">
zu
</code>
</div>
</div>
</td>
<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>
<code class="leafygreen-ui-1l06pbn">
non-ignorable
</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>
<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>
|
https://www.mongodb.com/docs/manual/reference/operator/query-array/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Array Query Operators
<a class="headerlink leafygreen-ui-1kepx47" href="#array-query-operators" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="array-query-operators">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
Array operators return data based on array conditions.
</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 details on a specific operator, including syntax and examples,
click on the link to the operator's reference page.
</p>
</div>
</div>
<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>
Name
</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/query/all/#mongodb-query-op.-all">
<code class="leafygreen-ui-1l06pbn">
$all
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Matches arrays that contain all elements specified in the query.
</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/query/elemMatch/#mongodb-query-op.-elemMatch">
<code class="leafygreen-ui-1l06pbn">
$elemMatch
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Selects documents if element in the array field matches all the specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/elemMatch/#mongodb-query-op.-elemMatch">
<code class="leafygreen-ui-1l06pbn">
$elemMatch
</code>
</a>
conditions.
</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/query/size/#mongodb-query-op.-size">
<code class="leafygreen-ui-1l06pbn">
$size
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Selects documents if the array field is a specified size.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For examples on querying array fields, 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/">
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-array-of-documents/">
Query an Array of Embedded Documents
</a>
</p>
</li>
</ul>
</section>
|
https://www.mongodb.com/docs/manual/core/indexes/index-types/index-wildcard/index-wildcard-compound/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Compound Wildcard Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-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="compound-wildcard-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-x9koo9" href="#search-using-the-attribute-pattern" target="_self">
<span>
Search Using the Attribute Pattern
</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="#general-considerations-for-wildcard-indexes" target="_self">
<span>
General Considerations for Wildcard Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#compound-wildcard-index-considerations" target="_self">
<span>
Compound Wildcard Index Considerations
</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-x9koo9" href="#filter-fields-with-a-wildcardprojection" target="_self">
<span>
Filter Fields with a
<code class="css-1kekw28 e1wawog0">
wildcardProjection
</code>
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-a-helper-method-to-create-a-wildcard-index" target="_self">
<span>
Use a Helper Method to Create a Wildcard Index
</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>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
7.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports creating wildcard indexes on a field or a set of
fields. A compound index has multiple index terms. A compound wildcard
index has one wildcard term and one or more additional index terms.
</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">
Wildcard indexes do not replace workload-based index planning.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on creating indexes that support your workload, 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>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wc-compound-index-attrib-pattern">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Search Using the Attribute Pattern
<a class="headerlink leafygreen-ui-1kepx47" href="#search-using-the-attribute-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="search-using-the-attribute-pattern">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/blog/post/building-with-patterns-the-attribute-pattern" target="_self">
<span>
attribute pattern
</span>
</a>
is a useful technique for searching documents that share common
characteristics.
</p>
<p class="leafygreen-ui-1kp3ins">
Unfortunately, it is expensive to create a lot of individual indexes to
cover all of the possible queries. A wildcard index is a good
alternative to creating a large number of individual indexes because one
wildcard index can efficiently cover many potential queries.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider a schema like:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n tenantId: <number>,\n tenantRegion: <number>,\n customFields: {\n addr: <string>,\n name: <string>,\n blockId: <number>,\n ...\n }\n dateOpened: <date>\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">tenantId</span>: <<span class="lg-highlight-title lg-highlight-class">Number</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tenantRegion</span>: <<span class="lg-highlight-title lg-highlight-class">Number</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">customFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">addr</span>: <<span class="lg-highlight-title lg-highlight-class">String</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <<span class="lg-highlight-title lg-highlight-class">String</span>><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">blockId</span>: <<span class="lg-highlight-title lg-highlight-class">Number</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">dateOpened</span>: <<span class="lg-highlight-title lg-highlight-class">Date</span>></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You might want to query aspects of the
<code class="leafygreen-ui-1l06pbn">
customFields
</code>
field for
tenants that have a particular
<code class="leafygreen-ui-1l06pbn">
tenantId
</code>
. You could create a series
of individual indexes:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ tenantId: 1, \"customFields.addr\": 1 }\n{ tenantId: 1, \"customFields.name\": 1 }\n{ tenantId: 1, \"customFields.blockId\": 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">{ <span class="lg-highlight-attr">tenantId</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customFields.addr"</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">tenantId</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customFields.name"</span>: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">tenantId</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customFields.blockId"</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>
<p class="leafygreen-ui-1kp3ins">
This approach is difficult to maintain and you are likely to reach the
maximum number of indexes per collection (64).
</p>
<p class="leafygreen-ui-1kp3ins">
Use a compound wildcard index instead. The compound wildcard index is
easier to write, easier to maintain, and is unlikely to reach the 64
index collection limit.
</p>
<p class="leafygreen-ui-1kp3ins">
This example creates a compound wildcard index on the
<code class="leafygreen-ui-1l06pbn">
salesData
</code>
collection:
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wc-ex-first">
</span>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n createIndexes: \"salesData\",\n indexes: [\n {\n key: {\n tenantId: 1,\n \"customFields.$**\": 1\n },\n name: \"tenant_customFields\"\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-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">"salesData"</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">tenantId</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customFields.$**"</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">"tenant_customFields"</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 wildcard,
<code class="leafygreen-ui-1l06pbn">
"customFields.$**"
</code>
, specifies all of the sub-fields in
the
<code class="leafygreen-ui-1l06pbn">
customFields
</code>
field. The other index term,
<code class="leafygreen-ui-1l06pbn">
tenantId
</code>
, is not a
wildcard specification; it is a standard field specification.
</p>
</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>
<p class="leafygreen-ui-1kp3ins">
To create wildcard indexes, use a standard index creation command:
</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/createIndexes/#mongodb-dbcommand-dbcmd.createIndexes">
<code class="leafygreen-ui-1l06pbn">
createIndexes
</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.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</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.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
createIndexes()
</code>
</a>
</p>
</li>
</ul>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
General Considerations for Wildcard Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#general-considerations-for-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="general-considerations-for-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 a 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":"db.salesData.createIndex(\n { \"$**\" : 1 },\n { \"wildcardProjection\" :\n { \"_id\": 1, \"customers.lastName\": 1, \"customers.FirstName\": 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">salesData</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">"$**"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</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">"_id"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customers.lastName"</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customers.FirstName"</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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can create more than one wildcard index on a collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A wildcard index may cover the same fields as other indexes in the
collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<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>
. They only
include entries for documents that contain the indexed field.
</p>
<p class="leafygreen-ui-1kp3ins">
The document is not indexed if all of the fields in the compound
wildcard index are missing.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compound Wildcard Index Considerations
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-wildcard-index-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="compound-wildcard-index-considerations">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Compound wildcard indexes are sparse indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Documents are included in the index if they are missing the wildcard
field but have one of the compound fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Index fields, including wildcard fields, can be sorted in ascending
(
<code class="leafygreen-ui-1l06pbn">
1
</code>
) or descending (
<code class="leafygreen-ui-1l06pbn">
-1
</code>
) order.
</p>
</li>
</ul>
</section>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wc-compound-index-wcProject">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Filter Fields with a
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#filter-fields-with-a-wildcardprojection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="filter-fields-with-a-wildcardprojection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can use a
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
to specify individual sub-fields.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-wc-ex-second">
</span>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.runCommand(\n {\n createIndexes: \"salesData\",\n indexes: [\n {\n key: {\n tenantId: 1,\n \"$**\": 1\n },\n name: \"tenant_customFields_projection\",\n wildcardProjection: {\n \"customFields.addr\": 1,\n \"customFields.name\": 1\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-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">"salesData"</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">tenantId</span>: <span class="lg-highlight-number">1</span>,</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"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"tenant_customFields_projection"</span>,</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">"customFields.addr"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customFields.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"> }</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 wildcard index term,
<code class="leafygreen-ui-1l06pbn">
"$**"
</code>
, specifies every field in the
collection. The
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
limits the index to the specified
fields,
<code class="leafygreen-ui-1l06pbn">
"customFields.addr"
</code>
and
<code class="leafygreen-ui-1l06pbn">
"customFields.name"
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
You can only use a
<code class="leafygreen-ui-1l06pbn">
wildcardProjection
</code>
when the wildcard term is
<code class="leafygreen-ui-1l06pbn">
$**
</code>
.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use a Helper Method to Create a Wildcard Index
<a class="headerlink leafygreen-ui-1kepx47" href="#use-a-helper-method-to-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="use-a-helper-method-to-create-a-wildcard-index">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB provides
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/#std-label-js-administrative-methods">
shell helper methods
</a>
for most
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/#std-label-database-commands">
database commands
</a>
. These shell
methods offer a simplified syntax and are functionally equivalent to
the database commands.
</p>
<p class="leafygreen-ui-1kp3ins">
The shell helper for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ex-first" target="_self">
<span>
first example
</span>
</a>
is:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.salesData.createIndex(\n { tenantId: 1, \"customFields.$**\": 1 },\n {\n name: \"tenant_customFields_shellHelper\"\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">salesData</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">tenantId</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"customFields.$**"</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">"tenant_customFields_shellHelper"</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 shell helper for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-wc-ex-second" target="_self">
<span>
second example
</span>
</a>
is:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.salesData.createIndex(\n { tenantId: 1, \"$**\": 1 },\n { \"wildcardProjection\": {\n \"customFields.addr\": 1,\n \"customFields.name\": 1\n },\n name: \"tenant_customFields_projection_helper\"\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">salesData</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">tenantId</span>: <span class="lg-highlight-number">1</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-string">"wildcardProjection"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customFields.addr"</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"customFields.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">"tenant_customFields_projection_helper"</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">
If you want to compare the shell commands and the database commands, you
must drop the indexes between command invocations. You cannot create
the same index twice, even with different names.
</p>
<p class="leafygreen-ui-1kp3ins">
To drop an index, insert the index name and run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.dropIndex/#std-label-collection-drop-index">
db.collection.dropIndex()
<!-- -->
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.salesData.dropIndex( \"tenant_customFields\" )","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">salesData</span>.<span class="lg-highlight-title lg-highlight-function">dropIndex</span>( <span class="lg-highlight-string">"tenant_customFields"</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 preceding command removes the
<code class="leafygreen-ui-1l06pbn">
"tenant_customFields"
</code>
index from
the
<code class="leafygreen-ui-1l06pbn">
salesData
</code>
database.
</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-wildcard/#std-label-wildcard-index-details">
Behavioral details for wildcard 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/create-wildcard-index-single-field/#std-label-wildcard-index-single">
Single wildcard 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/create-wildcard-text-index/#std-label-create-wildcard-text-index">
Wildcard text indexes
</a>
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$toLong (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-tolong--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="-tolong--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">
$toLong
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-toLong" 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.-toLong">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Converts a value to a long. If the value cannot be converted
to a long,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toLong" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toLong
</code>
</span>
</a>
errors. If the value is null or
missing,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toLong" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toLong
</code>
</span>
</a>
returns null.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toLong" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toLong
</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 $toLong: <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">$toLong</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.-toLong" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toLong
</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.-toLong" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toLong
</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: \"long\" } }","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">"long"</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
long:
</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>
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>
Boolean
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
Returns Long(0) for
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</div>
<div class="line">
Returns Long(1) for
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</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>
<p class="leafygreen-ui-1kp3ins">
Returns truncated value.
</p>
<p class="leafygreen-ui-1kp3ins">
The truncated double value must fall within the minimum and
maximum value for a long.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot convert a double value whose truncated value is less
than the minimum long value or is greater than the maximum
long value.
</p>
</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>
<p class="leafygreen-ui-1kp3ins">
Returns truncated value.
</p>
<p class="leafygreen-ui-1kp3ins">
The truncated decimal value must fall within the minimum and
maximum value for a long.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot convert a decimal value whose truncated value is less
than the minimum long value or is greater than the maximum
long value.
</p>
</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>
Returns the int value as a long.
</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>
No-op. Returns the long value.
</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>
<p class="leafygreen-ui-1kp3ins">
Returns the numerical value of the string.
</p>
<p class="leafygreen-ui-1kp3ins">
The string value must be of a base
<sub>
10
</sub>
long (e.g.
<code class="leafygreen-ui-1l06pbn">
"-5"
</code>
,
<code class="leafygreen-ui-1l06pbn">
"123456"
</code>
).
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot convert a string value of a float or decimal or
non-base
<sub>
10
</sub>
number (e.g.
<code class="leafygreen-ui-1l06pbn">
"-5.0"
</code>
,
<code class="leafygreen-ui-1l06pbn">
"0x6400"
</code>
)
</p>
</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>
Converts the Date into the number of milliseconds since the
epoch.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The following table lists some conversion to long examples:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:67%"/>
<col style="width:33%"/>
</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">
{ $toLong: true }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("1")
</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">
{ $toLong: false }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("0")
</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">
{ $toLong: 1.99999 }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("1")
</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">
{ $toLong: NumberDecimal("5.5000") }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("5")
</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">
{ $toLong: NumberDecimal("9223372036854775808.0") }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Error
</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">
{ $toLong: NumberInt(8) }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long(8)
</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">
{ $toLong: ISODate("2018-03-26T04:38:28.044Z") }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("1522039108044")
</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">
{ $toLong: "-2" }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Long("-2")
</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">
{ $toLong: "2.5" }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Error
</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">
{ $toLong: 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: NumberInt(5) },\n { _id: 2, item: \"pie\", qty: \"100\" },\n { _id: 3, item: \"ice cream\", qty: NumberLong(\"500\") },\n { _id: 4, item: \"almonds\", qty: \"50\" },\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">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-title lg-highlight-class">NumberInt</span>(<span class="lg-highlight-number">5</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-string">"100"</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">qty</span>: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"500"</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-string">"50"</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">
qty
</code>
to long before sorting by the value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Define stage to add convertedQty field with converted qty value\n\nqtyConversionStage = {\n $addFields: {\n convertedQty: { $toLong: \"$qty\" }\n }\n};\n\n// Define stage to sort documents by the converted qty values\n\nsortStage = {\n $sort: { \"convertedQty\": -1 }\n};\n\n\ndb.orders.aggregate( [\n qtyConversionStage,\n sortStage\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 convertedQty</span><span class="lg-highlight-comment"> field with converted </span><span class="lg-highlight-comment">qty value</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">qtyConversionStage <!-- -->= <!-- -->{</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">convertedQty</span>: <!-- -->{ <span class="lg-highlight-attr">$toLong</span>: <span class="lg-highlight-string">"$qty"</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"><span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> Define stage to </span><span class="lg-highlight-comment">sort documents by</span><span class="lg-highlight-comment"> the converted qty </span><span class="lg-highlight-comment">values</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">sortStage <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-string">"convertedQty"</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"><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">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"> <!-- -->qtyConversionStage<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->sortStage</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 documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 3, item: 'ice cream', qty: Long(\"500\"), convertedQty: Long(\"500\") },\n{ _id: 2, item: 'pie', qty: '100', convertedQty: Long(\"100\") },\n{ _id: 4, item: 'almonds', qty: '50', convertedQty: Long(\"50\") },\n{ _id: 1, item: 'apple', qty: 5, convertedQty: Long(\"5\") }","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">3</span>, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">'ice cream'</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"500"</span>)<!-- -->, <span class="lg-highlight-attr">convertedQty</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"500"</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-string">'100'</span>, <span class="lg-highlight-attr">convertedQty</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"100"</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-string">'50'</span>, <span class="lg-highlight-attr">convertedQty</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"50"</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">convertedQty</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"5"</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/reference/method/sh.updateZoneKeyRange/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
sh.updateZoneKeyRange()
<a class="headerlink leafygreen-ui-1kepx47" href="#sh.updatezonekeyrange--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.updatezonekeyrange--">
</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="#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="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange(namespace, minimum, maximum, zone)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.updateZoneKeyRange" 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.updateZoneKeyRange">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Associates a range of shard key values with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone">
zone
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</a>
database command and its helpers
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange">
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</a>
on
an unsharded collection or a non-existing collection.
</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/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
takes the following arguments:
</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">
namespace
</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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-namespace">
namespace
</a>
of the sharded collection associate with the
<code class="leafygreen-ui-1l06pbn">
zone
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The collection must be sharded for the operation to succeed.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
minimum
</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 inclusive lower bound of the range of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify each field of the shard key in the form of
<code class="leafygreen-ui-1l06pbn">
<fieldname> : <value>
</code>
.
The value must be of the same BSON type or types as the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
To use hashed sharding, the field value needs to be of type
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
<code class="leafygreen-ui-1l06pbn">
NumberLong
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
maximum
</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 exclusive upper bound of the range of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify each field of the shard key in the form of
<code class="leafygreen-ui-1l06pbn">
<fieldname> : <value>
</code>
.
The value must be of the same BSON type or types as the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
To use hashed sharding, the field value needs to be of type
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
<code class="leafygreen-ui-1l06pbn">
NumberLong
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zone
</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 zone to associate with the range of shard key values bounded
by
<code class="leafygreen-ui-1l06pbn">
minimum
</code>
and
<code class="leafygreen-ui-1l06pbn">
maximum
</code>
.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Only issue
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
when connected 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.
</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">
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">
You cannot create a range of shard key values whose lower and upper boundaries
overlap with an existing range for the sharded collection. For example, given
an existing range of
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
10
</code>
, you cannot create a new range of
<code class="leafygreen-ui-1l06pbn">
5
</code>
to
<code class="leafygreen-ui-1l06pbn">
20
</code>
, as the new range would overlap with the existing range.
</p>
<p class="leafygreen-ui-1kp3ins">
A zone can have multiple ranges of data associated with it, but a range
can at most be associated with a single zone.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zone
</a>
manual page for more information on zones
in sharded clusters.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updateZoneKeyRange-method-init-chunk-distribution">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initial Chunk Distribution for Empty or Non-Existing Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-for-empty-or-non-existing-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="initial-chunk-distribution-for-empty-or-non-existing-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you are considering performing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zone sharding
</a>
on an empty or non-existent collection, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
to create the zones and zone ranges
<em>
before
</em>
sharding the collection (
<em>
since 4.0.2
</em>
). Starting in version
4.0.3, creating zones and zone ranges on empty or non-existing
collections allows MongoDB to optimize the initial chunk creation and
distribution process when sharding the collection. This optimized
process supports faster setup of zoned sharding with less balancer
overhead than creating zones after sharding. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
performs all chunk management after the optimized
initial chunk creation and distribution.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example of defining zones and zone ranges for initial chunk
distribution, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-pre-define-zone-range-example" target="_self">
<span>
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updateZoneKeyRange-method-init-chunk-distribution-compound-hashed">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Initial Chunk Distribution with Compound Hashed Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-with-compound-hashed-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="initial-chunk-distribution-with-compound-hashed-shard-keys">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports sharding collections on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
compound hashed indexes
</a>
. MongoDB can
perform optimized initial chunk creation and distribution when sharding
the empty or non-existing collection on a compound hashed shard key.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-10">
<div aria-label="Tabs to describe usage of hash-not-prefix/hash-prefix" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_ajs5h4gl0" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_ae4tdrh82" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field Is Prefix
</div>
</button>
<button aria-controls="_d8htp6w2p" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_stw53wc51" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field is Not Prefix
</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="_3l32fqowp" class="" id="_4pgl196ao" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is the prefix of the shard key (i.e. the first
field in the shard key), all of the following must be true for
MongoDB to perform initial chunk creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has a single zone range with
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
all lower-bound fields and
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
for all upper-bound
fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
<div>
<div aria-labelledby="_vuery2y52" class="leafygreen-ui-38lglc" id="_zwxtjhg3c" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is
<em>
not
</em>
the prefix of the shard key (i.e.
the shard key has one or more non-hashed leading fields), all of
the following must be true for MongoDB to perform initial chunk
creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has one zone range for each combination of distinct
prefix field values (i.e. all fields preceding the hashed field).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the lower-bound of each zone range, specify
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
the hashed field and all subsequent fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For each zone range, at least one upper-bound prefix field
<em>
must
</em>
differ from its lower-bound counterpart.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For a more complete example of defining zones and zone ranges for
initial chunk distribution on a compound hashed shard key, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-pre-define-zone-range-hashed-example" target="_self">
<span>
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</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">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
<code class="leafygreen-ui-1l06pbn">
sh.balancerCollectionStatus()
</code>
</a>
</p>
</div>
</div>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Balancer
<a class="headerlink leafygreen-ui-1kepx47" href="#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="balancer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
After associating a range to a zone, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing-internals">
balancer
</a>
must first run in order to migrate any chunks
whose ranges are covered by the zone to shards inside of that zone. Until
balancing completes, some chunks may reside on the wrong shard given the
configured zones for the sharded cluster. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding-balancer">
Balancer
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
sharded cluster balancer
</a>
manual page for
more information on how migrations work in a sharded cluster.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Bounds
<a class="headerlink leafygreen-ui-1kepx47" href="#bounds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="bounds">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Zone ranges are always inclusive of the lower boundary and exclusive
of the upper boundary.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Dropped Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#dropped-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">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Dropping a collection deletes its associated zone/tag ranges.
</p>
<p class="leafygreen-ui-1kp3ins">
In earlier versions, MongoDB does not remove the tag associations for a
dropped collection, and if you later create a new collection with the
same name, the old tag associations will apply to the new collection.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Security
<a class="headerlink leafygreen-ui-1kepx47" href="#security" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="security">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For sharded clusters running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication
</a>
, you
must authenticate as either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a user whose privileges include the specified actions on various
collections in the
<code class="leafygreen-ui-1l06pbn">
config
</code>
database:
</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/privilege-actions/#mongodb-authaction-find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
config.shards
</code>
collection
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
config.tags
</code>
collection;
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
or, alternatively,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a user whose privileges include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding">
<code class="leafygreen-ui-1l06pbn">
enableSharding
</code>
</a>
on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-collection">
cluster
</a>
resource.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
<code class="leafygreen-ui-1l06pbn">
clusterManager
</code>
</a>
built-in roles have
the appropriate permissions for issuing
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
. See
the documentation page for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
Role-Based Access Control
</a>
for more information.
</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>
<p class="leafygreen-ui-1kp3ins">
Given a sharded collection
<code class="leafygreen-ui-1l06pbn">
exampledb.collection
</code>
with a shard key of
<code class="leafygreen-ui-1l06pbn">
{ a
: 1 }
</code>
, the following operation creates a range with a lower bound of
<code class="leafygreen-ui-1l06pbn">
1
</code>
and an upper bound of
<code class="leafygreen-ui-1l06pbn">
10
</code>
on the
<code class="leafygreen-ui-1l06pbn">
alpha
</code>
zone:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"exampledb.collection\",\n { a : 1 },\n { a : 10 },\n \"alpha\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</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">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 removes the previously created range by passing
<code class="leafygreen-ui-1l06pbn">
null
</code>
to the
<code class="leafygreen-ui-1l06pbn">
zone
</code>
field.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"exampledb.collection\",\n { a : 1 },\n { a : 10 },\n null\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <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>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
min
</code>
and
<code class="leafygreen-ui-1l06pbn">
max
</code>
must match exactly the bounds of the target range.
The following operation attempts to remove the previously created range, but
specifies
<code class="leafygreen-ui-1l06pbn">
{ a : 0 }
</code>
as the
<code class="leafygreen-ui-1l06pbn">
min
</code>
bound:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"exampledb.collection\",\n { a : 0 },\n { a : 10 },\n null\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <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>
<p class="leafygreen-ui-1kp3ins">
While the range of
<code class="leafygreen-ui-1l06pbn">
{ a : 0 }
</code>
and
<code class="leafygreen-ui-1l06pbn">
{ a : 10 }
</code>
encompasses the existing
range, it is not an exact match and therefore
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</a>
does not remove anything.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compound Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-shard-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="compound-shard-key">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Given a sharded collection
<code class="leafygreen-ui-1l06pbn">
exampledb.collection
</code>
with a shard key of
<code class="leafygreen-ui-1l06pbn">
{ a
: 1, b : 1 }
</code>
, the following operation creates a range covering the lower
bound of
<code class="leafygreen-ui-1l06pbn">
{ a: 1, b : 1 }
</code>
and an upper bound of
<code class="leafygreen-ui-1l06pbn">
{ a : 10, b : 10}
</code>
and associates it
with the
<code class="leafygreen-ui-1l06pbn">
alpha
</code>
zone:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"exampledb.collection\",\n { a : 1, b : 1 },\n { a : 10, b : 10 },\n \"alpha\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">10</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">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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-pre-define-zone-range-example">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-pre-define-zone-range-hashed-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#pre-define-zones-and-zone-ranges-for-an-empty-or-non-existing-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="pre-define-zones-and-zone-ranges-for-an-empty-or-non-existing-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you create zones and zone ranges on empty or non-existing collections,
MongoDB may optimize the initial chunk creation and distribution process when
sharding the collection. This optimized process supports faster setup of zoned
sharding with less balancer overhead than creating zones after sharding. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
performs all chunk management after the
optimized initial chunk creation and distribution. For more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution-compound-hashed" target="_self">
<span>
Initial Chunk Distribution with Compound Hashed Shard Keys
</span>
</a>
for more information.
</p>
<p class="leafygreen-ui-1kp3ins">
The sections below contain examples for three different shard key types.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following examples, which explore pre-defining zones or
zone ranges for three different shard key types:
</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-updatezonekeyrange-single-or-compound-example" target="_self">
<span>
Single or Compound Shard Keys
</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-updatezonekeyrange-compound-prefix-hashed-example" target="_self">
<span>
Compound Hashed Shard Key with Hashed Prefix
</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-updatezonekeyrange-compound-non-prefix-hashed-example" target="_self">
<span>
Compound Hashed Shard Key with Non-Prefix Hashed Field
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-single-or-compound-example">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Single or Compound Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#single-or-compound-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="single-or-compound-shard-keys">
</div>
</a>
</h4>
<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 example only applies to single-field or compound shard keys
<em>
without
</em>
a hashed field.
</p>
<p class="leafygreen-ui-1kp3ins">
For example,
<code class="leafygreen-ui-1l06pbn">
{ "zip" : 1 }
</code>
or
<code class="leafygreen-ui-1l06pbn">
{ "zip" : 1, "account" : 1}
</code>
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesUse sh.addShardToZone() to create the zones:"},{"@type":"HowToStep","text":"Create the Zone RangesUse sh.updateZoneKeyRange() to create the ranges\nfor the empty contacts collection in the exampledb\ndatabase:"},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() to shard the collection contacts:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The method returns:For the collection, sharding operation created 5 chunks (two chunks\nthat correspond to the zone ranges and the other three to cover all\nother values) across shardA and shardB."}],"name":"Single or Compound Shard Keys","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">
Create the Zones
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-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="create-the-zones">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
<code class="leafygreen-ui-1l06pbn">
sh.addShardToZone()
</code>
</a>
to create the zones:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"DC1\")\nsh.addShardToZone(\"shardB\", \"DC2\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"DC1"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"DC2"</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>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the Zone Ranges
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zone-ranges" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-zone-ranges">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
to create the ranges
for the empty
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
exampledb
</code>
database:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"exampledb.contacts\",\n { zip: 10001 },\n { zip: 10090 },\n \"DC1\"\n);\n\nsh.updateZoneKeyRange(\n \"exampledb.contacts\",\n { zip: 90001 },\n { zip: 96054 },\n \"DC2\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.contacts"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10001</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">10090</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"DC1"</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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"exampledb.contacts"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">90001</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-number">96054</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"DC2"</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>
</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">
Shard the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-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="shard-the-collection">
</div>
</a>
</h5>
<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 collection does not exist, the sharding operation creates
the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
to shard the collection
<code class="leafygreen-ui-1l06pbn">
contacts
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\"exampledb.contacts\", { zip: 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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(<span class="lg-highlight-string">"exampledb.contacts"</span>, <!-- -->{ <span class="lg-highlight-attr">zip</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>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Review the Created Chunks and Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-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="review-the-created-chunks-and-distribution">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
To see the created chunks and distribution, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
<code class="leafygreen-ui-1l06pbn">
sh.status()
</code>
</a>
operation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","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">status</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 method returns:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n sharding version: {\n \"_id\" : 1,\n \"minCompatibleVersion\" : 5,\n \"currentVersion\" : 6,\n \"clusterId\" : ObjectId(\"5b80c06d35a961fd0ae1986d\")\n }\n shards:\n { \"_id\" : \"shardA\", \"host\" : \"shardA/mongodb0.example.net:27018,mongodb1.example.net:27018,mongodb2.example.net:27018\", \"state\" : 1, \"tags\" : [ \"DC1\" ] }\n { \"_id\" : \"shardB\", \"host\" : \"shardB/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018\", \"state\" : 1, \"tags\" : [ \"DC2\" ] }\n active mongoses:\n \"4.2.0\" : 2\n autosplit:\n Currently enabled: yes\n balancer:\n Currently enabled: yes\n Currently running: no\n Failed balancer rounds in last 5 attempts: 0\n Migration Results for the last 24 hours:\n No recent migrations\n databases:\n { \"_id\" : \"config\", \"primary\" : \"config\" }\n { \"_id\" : \"exampledb\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"6c351bcf-acd2-4fd9-82d8-9f6bd7321558\"), \"lastMod\" : 1 } }\n exampledb.contacts\n shard key: { \"zip\" : 1 }\n unique: false\n balancing: true\n chunks:\n shardA 3\n shardB 2\n { \"zip\" : { \"$minKey\" : 1 } } -->> { \"zip\" : 10001 } on : shardA Timestamp(1, 0)\n { \"zip\" : 10001 } -->> { \"zip\" : 10090 } on : shardA Timestamp(1, 1)\n { \"zip\" : 10090 } -->> { \"zip\" : 90001 } on : shardB Timestamp(1, 2)\n { \"zip\" : 90001 } -->> { \"zip\" : 96054 } on : shardB Timestamp(1, 3)\n { \"zip\" : 96054 } -->> { \"zip\" : { \"$maxKey\" : 1 } } on : shardA Timestamp(1, 4)\n tag: DC1 { \"zip\" : 10001 } -->> { \"zip\" : 10090 }\n tag: DC2 { \"zip\" : 90001 } -->> { \"zip\" : 96054 }","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-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</span> <!-- -->-<!-- -->-<!-- -->-</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->sharding <span class="lg-highlight-attr">version</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">"minCompatibleVersion"</span> <!-- -->: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"currentVersion"</span> <!-- -->: <span class="lg-highlight-number">6</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clusterId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5b80c06d35a961fd0ae1986d"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">shards</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"shardA/mongodb0.example.net:27018,mongodb1.example.net:27018,mongodb2.example.net:27018"</span>, <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"DC1"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"host"</span> <!-- -->: <span class="lg-highlight-string">"shardB/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018"</span>, <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"tags"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-string">"DC2"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> active <span class="lg-highlight-attr">mongoses</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"4.2.0"</span> <!-- -->: <span class="lg-highlight-number">2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">autosplit</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">enabled</span>: <!-- -->yes</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">balancer</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">enabled</span>: <!-- -->yes</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Currently</span> <span class="lg-highlight-attr">running</span>: <!-- -->no</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Failed</span> balancer rounds <span class="lg-highlight-keyword">in</span> last <span class="lg-highlight-number">5</span> <span class="lg-highlight-attr">attempts</span>: <span class="lg-highlight-number">0</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">Migration</span> <span class="lg-highlight-title lg-highlight-class">Results</span> <span class="lg-highlight-keyword">for</span> the last <span class="lg-highlight-number">24</span> <span class="lg-highlight-attr">hours</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-class">No</span> recent migrations</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"exampledb"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"6c351bcf-acd2-4fd9-82d8-9f6bd7321558"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> exampledb.<span class="lg-highlight-property">contacts</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->shardA <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> shardB <span class="lg-highlight-number">2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</span> } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">4</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">DC1</span> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10001</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">10090</span> }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">DC2</span> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">90001</span> } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"zip"</span> <!-- -->: <span class="lg-highlight-number">96054</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 the collection, sharding operation created 5 chunks (two chunks
that correspond to the zone ranges and the other three to cover all
other values) across shardA and shardB.
</p>
</section>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-compound-prefix-hashed-example">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Compound Hashed Shard Key with Hashed Prefix
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-hashed-shard-key-with-hashed-prefix" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-hashed-shard-key-with-hashed-prefix">
</div>
</a>
</h4>
<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 example only applies to compound hashed shard keys where the
hashed field is the prefix of the shard key (i.e. the first field in
the shard key is hashed).
</p>
<p class="leafygreen-ui-1kp3ins">
For example,
<code class="leafygreen-ui-1l06pbn">
{ "_id" : "hashed", "facility" : 1 }
</code>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports sharding collections on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
compound hashed indexes
</a>
. When
sharding on a compound hashed shard key, MongoDB can perform
optimized initial chunk creation and distribution on the empty or
non-existing collection
<em>
only if
</em>
the defined zone ranges meet
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution" target="_self">
<span>
additional requirements
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Consider an empty collection
<code class="leafygreen-ui-1l06pbn">
examples.metrics
</code>
which will store
analytics from one of two manufacturing facilities. The
planned shard key is
<code class="leafygreen-ui-1l06pbn">
{ "_id" : "hashed", "facility" : 1}
</code>
,
where the hashed field is the shard key
<em>
prefix
</em>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesThe planned shard key is { \"_id\" : \"hashed\", \"facility\" : 1 }.\nSince the hashed field is the prefix (i.e. the first field in the\nshard key), create a single zone using\nsh.addShardToZone():"},{"@type":"HowToStep","text":"Create the Zone RangesInitial chunk distribution on a compound hashed shard key with a\nhashed prefix requires a single zone range with MinKey for all\nlower-bound fields and MaxKey for all upper-bound fields.Use sh.updateZoneKeyRange() to create a single range:"},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() with\npresplitHashedZones: true to shard the\ncollection and perform initial chunk creation and distribution:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The output resembles the following\n(content omitted for readability):The sharding operation produced 4 chunks in total. Two chunks\ncorrespond to the absolute lower and upper bounds. One zone was\ncreated on shardA and shardB corresponding to\nFacilityAlpha. The zone was subdivided into 2 chunks using the\nhashed field."}],"name":"Compound Hashed Shard Key with Hashed Prefix","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">
Create the Zones
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zones-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="create-the-zones-1">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
The planned shard key is
<code class="leafygreen-ui-1l06pbn">
{ "_id" : "hashed", "facility" : 1 }
</code>
.
Since the hashed field is the prefix (i.e. the first field in the
shard key), create a
<em>
single
</em>
zone using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
<code class="leafygreen-ui-1l06pbn">
sh.addShardToZone()
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"FacilityAlpha\")\nsh.addShardToZone(\"shardB\", \"FacilityAlpha\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"FacilityAlpha"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"FacilityAlpha"</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>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the Zone Ranges
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zone-ranges-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="create-the-zone-ranges-1">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
Initial chunk distribution on a compound hashed shard key with a
hashed prefix requires a single zone range with
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for all
lower-bound fields and
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
for all upper-bound fields.
</p>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
to create a single range:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"examples.metrics\",\n { \"_id\" : MinKey, \"facility\" : MinKey },\n { \"_id\" : MaxKey, \"facility\" : MaxKey },\n \"FacilityAlpha\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MinKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">MaxKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"FacilityAlpha"</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>
</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">
Shard the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection-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="shard-the-collection-1">
</div>
</a>
</h5>
<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 collection does not exist, the sharding operation creates
the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
to shard the
collection and perform initial chunk creation and distribution:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\n \"examples.metrics\",\n { \"_id\" : \"hashed\", \"facility\" : 1 },\n false,\n { presplitHashedZones: 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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">presplitHashedZones</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>
</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">
Review the Created Chunks and Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-and-distribution-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="review-the-created-chunks-and-distribution-1">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
To see the created chunks and distribution, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
<code class="leafygreen-ui-1l06pbn">
sh.status()
</code>
</a>
operation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","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">status</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 output resembles the following
(
<em>
content omitted for readability
</em>
):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n\ndatabases:\n { \"_id\" : \"config\", \"primary\" : \"config\" }\n { \"_id\" : \"examples\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"245f8abf-a363-48b0-8208-2a5b577bbb4e\"), \"lastMod\" : 1 } }\n examples.metrics\n shard key: { \"_id\" : \"hashed\", \"facility\" : 1 }\n unique: false\n balancing: true\n chunks:\n shardA 2\n shardB 2\n { \"_id\" : { \"$minKey\" : 1 }, \"facility\" : { \"$minKey\" : 1 } } -->> { \"_id\" : NumberLong(\"-4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } on : shardA Timestamp(1, 0)\n { \"_id\" : NumberLong(\"-4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } -->> { \"_id\" : NumberLong(0), \"facility\" : { \"$minKey\" : 1 } } on : shardA Timestamp(1, 1)\n { \"_id\" : NumberLong(0), \"facility\" : { \"$minKey\" : 1 } } -->> { \"_id\" : NumberLong(\"4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } on : shardB Timestamp(1, 2)\n { \"_id\" : NumberLong(\"4611686018427387902\"), \"facility\" : { \"$minKey\" : 1 } } -->> { \"_id\" : { \"$maxKey\" : 1 }, \"facility\" : { \"$maxKey\" : 1 } } on : shardB Timestamp(1, 3)\n\n tag: FacilityAlpha { \"_id\" : { \"$minKey\" : 1 }, \"facility\" : { \"$minKey\" : 1 } } -->> { \"_id\" : { \"$maxKey\" : 1 }, \"facility\" : { \"$maxKey\" : 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">-<!-- -->-<!-- -->- <span class="lg-highlight-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</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-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"examples"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"245f8abf-a363-48b0-8208-2a5b577bbb4e"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> examples.<span class="lg-highlight-property">metrics</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>, <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->shardA <span class="lg-highlight-number">2</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> shardB <span class="lg-highlight-number">2</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"-4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardA <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"4611686018427387902"</span>)<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shardB <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityAlpha</span> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</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 sharding operation produced 4 chunks in total. Two chunks
correspond to the absolute lower and upper bounds. One zone was
created on
<code class="leafygreen-ui-1l06pbn">
shardA
</code>
and
<code class="leafygreen-ui-1l06pbn">
shardB
</code>
corresponding to
<code class="leafygreen-ui-1l06pbn">
FacilityAlpha
</code>
. The zone was subdivided into 2 chunks using the
hashed field.
</p>
</section>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updatezonekeyrange-compound-non-prefix-hashed-example">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Compound Hashed Shard Key with Non-Prefix Hashed Field
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-hashed-shard-key-with-non-prefix-hashed-field" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-hashed-shard-key-with-non-prefix-hashed-field">
</div>
</a>
</h4>
<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 example only applies to compound hashed shard keys where the
hashed field is
<em>
not
</em>
the prefix of the shard key (i.e. the first
field in the shard key is not hashed).
</p>
<p class="leafygreen-ui-1kp3ins">
For example,
<code class="leafygreen-ui-1l06pbn">
{ "facility" : 1, "_id" : "hashed" }
</code>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports sharding collections on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
compound hashed indexes
</a>
. When
sharding on a compound hashed shard key, MongoDB can perform
optimized initial chunk creation and distribution on the empty or
non-existing collection
<em>
only if
</em>
the defined zone ranges meet
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-updateZoneKeyRange-method-init-chunk-distribution" target="_self">
<span>
additional requirements
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Consider an empty collection
<code class="leafygreen-ui-1l06pbn">
examples.metrics
</code>
which will store
analytics from one of two manufacturing facilities. The planned
shard key is
<code class="leafygreen-ui-1l06pbn">
{ "facility" : 1, "_id" : "hashed" }
</code>
, where
the hashed field is
<em>
not
</em>
the shard key prefix.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
facility
</code>
field stores the name of the facility:
<code class="leafygreen-ui-1l06pbn">
"FacilityAlpha"
</code>
or
<code class="leafygreen-ui-1l06pbn">
"FacilityBaker"
</code>
. The
collection requires zone ranges on
<code class="leafygreen-ui-1l06pbn">
facility
</code>
to help isolate
data for each facility to specific shards.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field compensates for the low-cardinality of the
<code class="leafygreen-ui-1l06pbn">
facility
</code>
field. Hashing compensates for the
monotonically-increasing nature of the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create the ZonesUse the sh.addShardToZone() command to create the\nzones."},{"@type":"HowToStep","text":"Create the Zone RangesThe planned shard key is {\"facility\" : 1, \"_id\" : \"hashed\"}. The\nfacility field has two possible values: FacilityAlpha and\nFacilityBaker.Initial chunk distribution on a compound hashed shard key where the\nhashed field is not the prefix requires one zone range for each\ncombination of distinct prefix field values (i.e. all fields\npreceding the hashed field). Since facility has two distinct\nprefix values, the collection requires exactly two zone ranges\nthat cover those values.The lower bound range specifies MinKey for all non-prefix\nfields.The upper-bound range has at least one prefix field that\ndiffers from its lower-bound counterpart.Use sh.updateZoneKeyRange() to create the range for\n\"facility\": \"FacilityAlpha\":Since zone range upper bounds are exclusive, this range only\ncovers documents with the distinct shard key prefix value\n\"facilty\" : \"FacilityAlpha\" and all possible values of _id.Use sh.updateZoneKeyRange() to create the range for\n\"facility\": \"FacilityBaker\":While the upper bound of this range can technically\ncapture other values of facility, the initial chunk\ndistribution logic relies on the assumption that no other distinct\nvalues for facility exist. Since the collection only contains\ndocuments where facility is FacilityAlpha or\nFacilityBaker, this range only covers\ndocuments with the distinct shard key prefix value\n\"facility\" : \"FacilityBaker\" and all possible values of\n_id."},{"@type":"HowToStep","text":"Shard the CollectionIf the collection does not exist, the sharding operation creates\nthe collection.If the collection is empty and no index exists to support the\nshard key, the sharding operation creates the index.Use sh.shardCollection() with\npresplitHashedZones: true to shard the\ncollection and perform initial chunk creation and distribution:"},{"@type":"HowToStep","text":"Review the Created Chunks and DistributionTo see the created chunks and distribution, run the\nsh.status() operation:The output resembles the following\n(content omitted for readability):The sharding operation produced 6 chunks in total. Two chunks\ncorrespond to the absolute lower and upper bounds. Two zones were\ncreated, one on shardA and one on shardB, corresponding to\nFacilityAlpha and FacilityBaker. Each of these zones has been\nfurther subdivided into 2 chunks using the hashed field."}],"name":"Compound Hashed Shard Key with Non-Prefix Hashed Field","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">
Create the Zones
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zones-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="create-the-zones-2">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
<code class="leafygreen-ui-1l06pbn">
sh.addShardToZone()
</code>
</a>
command to create the
zones.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShardToZone(\"shardA\", \"FacilityAlpha\")\nsh.addShardToZone(\"shardB\", \"FacilityBaker\")","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">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"FacilityAlpha"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx">sh.<span class="lg-highlight-title lg-highlight-function">addShardToZone</span>(<span class="lg-highlight-string">"shardB"</span>, <span class="lg-highlight-string">"FacilityBaker"</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>
<h5 class="contains-headerlink leafygreen-ui-1vzlt5f">
Create the Zone Ranges
<a class="headerlink leafygreen-ui-1kepx47" href="#create-the-zone-ranges-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="create-the-zone-ranges-2">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
The planned shard key is
<code class="leafygreen-ui-1l06pbn">
{"facility" : 1, "_id" : "hashed"}
</code>
. The
<code class="leafygreen-ui-1l06pbn">
facility
</code>
field has two possible values:
<code class="leafygreen-ui-1l06pbn">
FacilityAlpha
</code>
and
<code class="leafygreen-ui-1l06pbn">
FacilityBaker
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Initial chunk distribution on a compound hashed shard key where the
hashed field is
<em>
not
</em>
the prefix requires one zone range for each
combination of distinct prefix field values (i.e. all fields
preceding the hashed field). Since
<code class="leafygreen-ui-1l06pbn">
facility
</code>
has two distinct
prefix values, the collection requires exactly two zone ranges
that cover those values.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The lower bound range specifies
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for all non-prefix
fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The upper-bound range has at least one prefix field that
differs from its lower-bound counterpart.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
to create the range for
<code class="leafygreen-ui-1l06pbn">
"facility": "FacilityAlpha"
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"examples.metrics\",\n { \"facility\": \"FacilityAlpha\", \"_id\" : MinKey },\n { \"facility\": \"FacilityBaker\", \"_id\" : MinKey },\n \"FacilityAlpha\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_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-string">"facility"</span>: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_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-string">"FacilityAlpha"</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">
Since zone range upper bounds are
<em>
exclusive
</em>
, this range only
covers documents with the distinct shard key prefix value
<code class="leafygreen-ui-1l06pbn">
"facilty" : "FacilityAlpha"
</code>
and all possible values of
<code class="leafygreen-ui-1l06pbn">
_id
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</span>
</a>
to create the range for
<code class="leafygreen-ui-1l06pbn">
"facility": "FacilityBaker"
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.updateZoneKeyRange(\n \"examples.metrics\",\n { \"facility\": \"FacilityBaker\", \"_id\" : MinKey },\n { \"facility\": MaxKey, \"_id\" : MinKey },\n \"FacilityBaker\"\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">sh.<span class="lg-highlight-title lg-highlight-function">updateZoneKeyRange</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span>: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_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-string">"facility"</span>: <span class="lg-highlight-title lg-highlight-class">MaxKey</span>, <span class="lg-highlight-string">"_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-string">"FacilityBaker"</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">
While the upper bound of this range can technically
capture other values of
<code class="leafygreen-ui-1l06pbn">
facility
</code>
, the initial chunk
distribution logic relies on the assumption that no other distinct
values for
<code class="leafygreen-ui-1l06pbn">
facility
</code>
exist. Since the collection only contains
documents where
<code class="leafygreen-ui-1l06pbn">
facility
</code>
is
<code class="leafygreen-ui-1l06pbn">
FacilityAlpha
</code>
or
<code class="leafygreen-ui-1l06pbn">
FacilityBaker
</code>
, this range only covers
documents with the distinct shard key prefix value
<code class="leafygreen-ui-1l06pbn">
"facility" : "FacilityBaker"
</code>
and all possible values of
<code class="leafygreen-ui-1l06pbn">
_id
</code>
.
</p>
</li>
</ul>
</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">
Shard the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-the-collection-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="shard-the-collection-2">
</div>
</a>
</h5>
<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 collection does not exist, the sharding operation creates
the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
If the collection is empty and no index exists to support the
shard key, the sharding operation creates the index.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
to shard the
collection and perform initial chunk creation and distribution:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.shardCollection(\n \"examples.metrics\",\n { \"facility\" : 1, \"_id\" : \"hashed\"},\n false,\n { presplitHashedZones: 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">sh.<span class="lg-highlight-title lg-highlight-function">shardCollection</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"examples.metrics"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">presplitHashedZones</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>
</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">
Review the Created Chunks and Distribution
<a class="headerlink leafygreen-ui-1kepx47" href="#review-the-created-chunks-and-distribution-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="review-the-created-chunks-and-distribution-2">
</div>
</a>
</h5>
<p class="leafygreen-ui-1kp3ins">
To see the created chunks and distribution, run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.status/#mongodb-method-sh.status">
<code class="leafygreen-ui-1l06pbn">
sh.status()
</code>
</a>
operation:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.status()","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">status</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 output resembles the following
(
<em>
content omitted for readability
</em>
):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"--- Sharding Status ---\n\n databases:\n { \"_id\" : \"config\", \"primary\" : \"config\" }\n { \"_id\" : \"examples\", \"primary\" : \"shardA\", \"version\" : { \"uuid\" : UUID(\"6c351bcf-acd2-4fd9-82d8-9f6bd7321558\"), \"lastMod\" : 1 } }\n examples.metrics\n shard key: { \"facility\" : 1, \"_id\" : \"hashed\" }\n unique: false\n balancing: true\n chunks:\n shardA 3\n shardB 3\n { \"facility\" : { \"$minKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } on : shard1 Timestamp(1, 0)\n { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : \"FacilityAlpha\", \"_id\" : NumberLong(0) } on : shard1 Timestamp(1, 1)\n { \"facility\" : \"FacilityAlpha\", \"_id\" : NumberLong(0) } -->> { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } on : shard1 Timestamp(1, 2)\n { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : \"FacilityBaker\", \"_id\" : NumberLong(0) } on : shard2 Timestamp(1, 3)\n { \"facility\" : \"FacilityBaker\", \"_id\" : NumberLong(0) } -->> { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } on : shard2 Timestamp(1, 4)\n { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$maxKey\" : 1 } } on : shard2 Timestamp(1, 5)\n\n tag: FacilityAlpha { \"facility\" : \"FacilityAlpha\", \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } }\n tag: FacilityBaker { \"facility\" : \"FacilityBaker\", \"_id\" : { \"$minKey\" : 1 } } -->> { \"facility\" : { \"$maxKey\" : 1 }, \"_id\" : { \"$minKey\" : 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">-<!-- -->-<!-- -->- <span class="lg-highlight-title lg-highlight-class">Sharding</span> <span class="lg-highlight-title lg-highlight-class">Status</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-attr">databases</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"config"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"config"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"examples"</span>, <span class="lg-highlight-string">"primary"</span> <!-- -->: <span class="lg-highlight-string">"shardA"</span>, <span class="lg-highlight-string">"version"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"uuid"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-function">UUID</span>(<span class="lg-highlight-string">"6c351bcf-acd2-4fd9-82d8-9f6bd7321558"</span>)<!-- -->, <span class="lg-highlight-string">"lastMod"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> examples.<span class="lg-highlight-property">metrics</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> shard <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"hashed"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unique</span>: <span class="lg-highlight-literal">false</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">balancing</span>: <span class="lg-highlight-literal">true</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">chunks</span>:</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->shardA <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> shardB <span class="lg-highlight-number">3</span></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">0</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">1</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard1 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">2</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">3</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-number">0</span>) } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">4</span>)</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } on <!-- -->: <!-- -->shard2 <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1</span>, <span class="lg-highlight-number">5</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityAlpha</span> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityAlpha"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } }</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">tag</span>: <span class="lg-highlight-title lg-highlight-class">FacilityBaker</span> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <span class="lg-highlight-string">"FacilityBaker"</span>, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> } } <!-- -->-<!-- -->-<!-- -->>> <!-- -->{ <span class="lg-highlight-string">"facility"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$maxKey"</span> <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-string">"_id"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"$minKey"</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 sharding operation produced 6 chunks in total. Two chunks
correspond to the absolute lower and upper bounds. Two zones were
created, one on
<code class="leafygreen-ui-1l06pbn">
shardA
</code>
and one on
<code class="leafygreen-ui-1l06pbn">
shardB
</code>
, corresponding to
<code class="leafygreen-ui-1l06pbn">
FacilityAlpha
</code>
and
<code class="leafygreen-ui-1l06pbn">
FacilityBaker
</code>
. Each of these zones has been
further subdivided into 2 chunks using the hashed field.
</p>
</section>
</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/sh.addShardToZone/#mongodb-method-sh.addShardToZone">
<code class="leafygreen-ui-1l06pbn">
sh.addShardToZone()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.removeRangeFromZone/#mongodb-method-sh.removeRangeFromZone">
<code class="leafygreen-ui-1l06pbn">
sh.removeRangeFromZone()
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/dot-dollar-considerations/dollar-prefix/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Dollar-Prefixed Field Names
<a class="headerlink leafygreen-ui-1kepx47" href="#dollar-prefixed-field-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="dollar-prefixed-field-names">
</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="#insert-operations" target="_self">
<span>
Insert Operations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#document-replacing-updates" target="_self">
<span>
Document Replacing Updates
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#document-modifying-updates" target="_self">
<span>
Document Modifying Updates
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#updates-using-aggregation-pipelines" target="_self">
<span>
Updates Using Aggregation Pipelines
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#general-restrictions" target="_self">
<span>
General Restrictions
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This section summarizes how different insert and update operations
handle dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed field names.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Insert Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#insert-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="insert-operations">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed fields are permitted as top level and nested
field names for inserts.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.sales.insertOne( {\n \"$price\": 50.00,\n \"quantity\": 30\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">insertOne</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$price"</span>: <span class="lg-highlight-number">50.00</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"quantity"</span>: <span class="lg-highlight-number">30</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">
Dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed fields are permitted on inserts using otherwise
reserved words. Operator names like
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/inc/#mongodb-update-up.-inc">
<code class="leafygreen-ui-1l06pbn">
$inc
</code>
</a>
can be used as
field names as well as words like
<code class="leafygreen-ui-1l06pbn">
id
</code>
,
<code class="leafygreen-ui-1l06pbn">
db
</code>
, and
<code class="leafygreen-ui-1l06pbn">
ref
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.books.insertOne( {\n \"$id\": \"h1961-01\",\n \"location\": {\n \"$db\": \"novels\",\n \"$ref\": \"2007042768\",\n \"$inc\": 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">books</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$id"</span>: <span class="lg-highlight-string">"h1961-01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"location"</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$db"</span>: <span class="lg-highlight-string">"novels"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$ref"</span>: <span class="lg-highlight-string">"2007042768"</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$inc"</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">
An update which creates a new document during an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upsert
</a>
is
treated as an
<code class="leafygreen-ui-1l06pbn">
insert
</code>
rather than an
<code class="leafygreen-ui-1l06pbn">
update
</code>
for field name
validation.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
Upserts
</a>
can accept dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed
fields. However,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upserts
</a>
are a special case and
similar update operations may cause an error if the
<code class="leafygreen-ui-1l06pbn">
match
</code>
portion
of the update selects an existing document.
</p>
<p class="leafygreen-ui-1kp3ins">
This code sample has
<code class="leafygreen-ui-1l06pbn">
upsert: true
</code>
so it will insert a new document
if the collection doesn't already contain a document that matches the
query term,
<code class="leafygreen-ui-1l06pbn">
{ "date": "2021-07-07" }
</code>
. If this sample code matches
an existing document, the update will fail since
<code class="leafygreen-ui-1l06pbn">
$hotel
</code>
is dollar
(
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.expenses.updateOne(\n { \"date\": \"2021-07-07\" },\n { $set: {\n \"phone\": 25.17,\n \"$hotel\": 320.10\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">expenses</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"date"</span>: <span class="lg-highlight-string">"2021-07-07"</span> }<!-- -->,</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">"phone"</span>: <span class="lg-highlight-number">25.17</span>,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$hotel"</span>: <span class="lg-highlight-number">320.10</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>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Document Replacing Updates
<a class="headerlink leafygreen-ui-1kepx47" href="#document-replacing-updates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-replacing-updates">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Update operators either replace existing fields with new documents
or else modify those fields. In cases where the update performs a
replacement, dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed fields are not permitted as top
level field names.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider a document like
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": \"E123\",\n \"address\": {\n \"$number\": 123,\n \"$street\": \"Elm Road\"\n },\n \"$rooms\": {\n \"br\": 2,\n \"bath\": 1\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": "E123",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "address": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$number": 123,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$street": "Elm Road"</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$rooms": {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "br": 2,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "bath": 1</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">
You could use an update operator that replaces an existing document to
modify the
<code class="leafygreen-ui-1l06pbn">
address.$street
</code>
field but you could not update the
<code class="leafygreen-ui-1l06pbn">
$rooms
</code>
field that way.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.housing.updateOne(\n { \"_id\": \"E123\" },\n { $set: { \"address.$street\": \"Elm Ave\" } }\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.housing.updateOne(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { "_id": "E123" },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> { $set: { "address.$street": "Elm Ave" } }</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">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
<code class="leafygreen-ui-1l06pbn">
$setField
</code>
</a>
as part of an aggregation pipeline to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-dotDollar-aggregate-update" target="_self">
<span>
update top level
</span>
</a>
dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
)
prefixed fields like
<code class="leafygreen-ui-1l06pbn">
$rooms
</code>
.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Document Modifying Updates
<a class="headerlink leafygreen-ui-1kepx47" href="#document-modifying-updates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-modifying-updates">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
When an update modifies, rather than replaces, existing document
fields, dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed fields can be top level field names.
Subfields can be accessed directly, but you need a helper method to
access the top level fields.
</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/operator/aggregation/getField/#mongodb-expression-exp.-getField">
<code class="leafygreen-ui-1l06pbn">
$getField
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
<code class="leafygreen-ui-1l06pbn">
$setField
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
<code class="leafygreen-ui-1l06pbn">
$literal
</code>
</a>
,
<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>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Consider a collection with documents like this inventory record:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: ObjectId(\"610023ad7d58ecda39b8d161\"),\n \"part\": \"AB305\",\n \"$bin\": 200,\n \"quantity\": 100,\n \"pricing\": { sale: true, \"$discount\": 60 }\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"> _id: ObjectId("610023ad7d58ecda39b8d161"),</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "part": "AB305",</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "$bin": 200,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "quantity": 100,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> "pricing": { sale: true, "$discount": 60 }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
pricing.$discount
</code>
subfield can be queried directly.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.findAndModify( {\n query: { \"part\": { $eq: \"AB305\" } },\n update: { $inc: { \"pricing.$discount\": 10 } }\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.inventory.findAndModify( {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> query: { "part": { $eq: "AB305" } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> update: { $inc: { "pricing.$discount": 10 } }</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">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField">
<code class="leafygreen-ui-1l06pbn">
$getField
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
<code class="leafygreen-ui-1l06pbn">
$literal
</code>
</a>
to access the
value of the top level
<code class="leafygreen-ui-1l06pbn">
$bin
</code>
field.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.findAndModify( {\n query: { $expr: {\n $eq: [ { $getField: { $literal: \"$bin\" } }, 200 ]\n } },\n update: { $inc: { \"quantity\": 10 } }\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.inventory.findAndModify( {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> query: { $expr: {</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> $eq: [ { $getField: { $literal: "$bin" } }, 200 ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> update: { $inc: { "quantity": 10 } }</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-dotDollar-aggregate-update">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Updates Using Aggregation Pipelines
<a class="headerlink leafygreen-ui-1kepx47" href="#updates-using-aggregation-pipelines" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="updates-using-aggregation-pipelines">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setField/#mongodb-expression-exp.-setField">
<code class="leafygreen-ui-1l06pbn">
$setField
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/getField/#mongodb-expression-exp.-getField">
<code class="leafygreen-ui-1l06pbn">
$getField
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
<code class="leafygreen-ui-1l06pbn">
$literal
</code>
</a>
in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceWith/#mongodb-pipeline-pipe.-replaceWith">
<code class="leafygreen-ui-1l06pbn">
$replaceWith
</code>
</a>
stage to modify
dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed fields in an aggregation
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pipeline">
pipeline
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Consider a collection of school records like:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\": 100001,\n \"$term\": \"fall\",\n \"registered\": true,\n \"grade\": 4\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">"_id"</span>: <span class="lg-highlight-number">100001</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$term"</span>: <span class="lg-highlight-string">"fall"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <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">"grade"</span>: <span class="lg-highlight-number">4</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a new collection for the spring semester using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-pipeline">
pipeline
</a>
to update the dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed
<code class="leafygreen-ui-1l06pbn">
$term
</code>
field.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.school.aggregate( [\n { $match: { \"registered\": true } },\n { $replaceWith: {\n $setField: {\n field: { $literal: \"$term\" },\n input: \"$$ROOT\",\n value: \"spring\"\n } } },\n { $out: \"spring2022\" }\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">school</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>: <!-- -->{ <span class="lg-highlight-string">"registered"</span>: <span class="lg-highlight-literal">true</span> } }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$replaceWith</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setField</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">field</span>: <!-- -->{ <span class="lg-highlight-attr">$literal</span>: <span class="lg-highlight-string">"$term"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$$ROOT"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">"spring"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$out</span>: <span class="lg-highlight-string">"spring2022"</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">
General Restrictions
<a class="headerlink leafygreen-ui-1kepx47" href="#general-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="general-restrictions">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In addition to the storage validation rules above, there are some
general restrictions on using dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed field names.
These fields cannot:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be indexed
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be used as part of a shard key
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be validated using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/jsonSchema/#mongodb-query-op.-jsonSchema">
<code class="leafygreen-ui-1l06pbn">
$jsonSchema
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be be modified with an escape sequence
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be used with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/security/client-side-field-level-encryption-guide/" target="_self">
<span>
Field Level Encryption
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Be used as a subfield in an
<code class="leafygreen-ui-1l06pbn">
_id
</code>
document
</p>
</li>
</ul>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Possible Data Loss With Dollar Signs ($) and Periods (.)
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
There is a small chance of data loss when using dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed
field names or field names that contain periods (
<code class="leafygreen-ui-1l06pbn">
.
</code>
) if these
field names are used in conjunction with unacknowledged writes
(
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
<code class="leafygreen-ui-1l06pbn">
w=0
</code>
) on servers
that are older than MongoDB 5.0.
</p>
<p class="leafygreen-ui-1kp3ins">
When running
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert">
<code class="leafygreen-ui-1l06pbn">
insert
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/update/#mongodb-dbcommand-dbcmd.update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify">
<code class="leafygreen-ui-1l06pbn">
findAndModify
</code>
</a>
commands, drivers that are 5.0 compatible
remove restrictions on using documents with field names that are
dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed or that contain periods (
<code class="leafygreen-ui-1l06pbn">
.
</code>
). These field
names generated a client-side error in earlier driver versions.
</p>
<p class="leafygreen-ui-1kp3ins">
The restrictions are removed regardless of the server version the
driver is connected to. If a 5.0 driver sends a document to an older
server, the document will be rejected without sending an error.
</p>
</div>
</div>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Import and Export Concerns With Dollar Signs ($) and Periods (.)
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, document field names can be dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
)
prefixed and can contain periods (
<code class="leafygreen-ui-1l06pbn">
.
</code>
). However,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoimport
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoexport
</code>
</span>
</a>
may not work
as expected in some situations with field names that make use of these
characters.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json/#std-label-extended-json-high-level-ref-v2">
MongoDB Extended JSON v2
</a>
cannot differentiate between type wrappers and fields that happen to
have the same name as type wrappers. Do not use Extended JSON
formats in contexts where the corresponding BSON representations
might include dollar (
<code class="leafygreen-ui-1l06pbn">
$
</code>
) prefixed keys. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-references/#std-label-dbref-explanation">
DBRef
</a>
mechanism is an exception to this
general rule.
</p>
<p class="leafygreen-ui-1kp3ins">
There are also restrictions on using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoimport/#mongodb-binary-bin.mongoimport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoimport
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/mongoexport/#mongodb-binary-bin.mongoexport" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
mongoexport
</code>
</span>
</a>
with periods (
<code class="leafygreen-ui-1l06pbn">
.
</code>
) in field names. Since
CSV files use the period (
<code class="leafygreen-ui-1l06pbn">
.
</code>
) to represent data hierarchies, a
period (
<code class="leafygreen-ui-1l06pbn">
.
</code>
) in a field name will be misinterpreted as a level of
nesting.
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/sh.moveChunk/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
sh.moveChunk()
<a class="headerlink leafygreen-ui-1kepx47" href="#sh.movechunk--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.movechunk--">
</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">
sh.moveChunk(namespace, query, destination)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.moveChunk" 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.moveChunk">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Moves the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunk
</a>
that contains the document specified by the
<code class="leafygreen-ui-1l06pbn">
query
</code>
to the
<code class="leafygreen-ui-1l06pbn">
destination
</code>
shard.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.moveChunk" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.moveChunk()
</code>
</span>
</a>
provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
database
command.
</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">
In most circumstances, allow the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-balancer">
balancer
</a>
to
automatically migrate
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunks
</a>
, and avoid calling
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.moveChunk" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.moveChunk()
</code>
</span>
</a>
directly.
</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">
This command cannot be used for hashed shard keys, as it
uses the
<code class="leafygreen-ui-1l06pbn">
find
</code>
option from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
command.
To move a chunk with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-hashed-shard-key">
hashed shard key
</a>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
command specifying the
<code class="leafygreen-ui-1l06pbn">
bounds
</code>
field.
</p>
</div>
</div>
<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/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.moveChunk" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.moveChunk()
</code>
</span>
</a>
takes the following arguments:
</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">
namespace
</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 sharded collection that contains the
chunk to migrate.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
query
</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>
An equality match on the shard key that selects the chunk to move.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
destination
</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 shard to move.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
By default, MongoDB cannot move a chunk if the number of documents
in the chunk is greater than 2 times the result of dividing the
configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-size">
chunk size
</a>
by the average
document size. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
command can specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#std-label-movechunk-forceJumbo">
forceJumbo
</a>
option to allow for the manual
migration of chunks too large to move, with or without the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-jumbo-chunk">
jumbo
</a>
label. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#std-label-movechunk-forceJumbo">
moveChunk
</a>
command for details.
</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">
<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/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitAt/#mongodb-method-sh.splitAt">
<code class="leafygreen-ui-1l06pbn">
sh.splitAt()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.splitFind/#mongodb-method-sh.splitFind">
<code class="leafygreen-ui-1l06pbn">
sh.splitFind()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/sharding/">
Sharding
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-chunk-migration">
chunk migration
</a>
</p>
</li>
</ul>
</div>
</div>
</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">
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">
Given the
<code class="leafygreen-ui-1l06pbn">
people
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
records
</code>
database, the
following operation finds the chunk that contains the documents with the
<code class="leafygreen-ui-1l06pbn">
zipcode
</code>
field set to
<code class="leafygreen-ui-1l06pbn">
53187
</code>
and then moves that chunk to the
shard named
<code class="leafygreen-ui-1l06pbn">
shard0019
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.moveChunk(\"records.people\", { zipcode: \"53187\" }, \"shard0019\")","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">sh.<span class="lg-highlight-title lg-highlight-function">moveChunk</span>(<span class="lg-highlight-string">"records.people"</span>, <!-- -->{ <span class="lg-highlight-attr">zipcode</span>: <span class="lg-highlight-string">"53187"</span> }<!-- -->, <span class="lg-highlight-string">"shard0019"</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/db.collection.checkMetadataConsistency/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.collection.checkMetadataConsistency()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.checkmetadataconsistency--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.collection.checkmetadataconsistency--">
</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="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.collection.checkMetadataConsistency(options)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.checkMetadataConsistency" 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.collection.checkMetadataConsistency">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Performs a series of consistency checks on sharding metadata
for the collection. The method returns a cursor with either all or a
batch of the inconsistency results found.
</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/checkMetadataConsistency/#mongodb-dbcommand-dbcmd.checkMetadataConsistency">
<code class="leafygreen-ui-1l06pbn">
checkMetadataConsistency
</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">
Run this method after major maintenance operations, such as upgrades and
downgrades, to check the state of the catalog.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, the method does not check indexes for consistency across the shards.
Index checks can return false positive inconsistencies if they run concurrent
with operations that create, delete, or modify indexes. To check indexes
with this method, set the
<code class="leafygreen-ui-1l06pbn">
checkIndexes
</code>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on the inconsistencies this method checks for,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/inconsistency-type/#std-label-inconsistency-types">
Inconsistency Types
<!-- -->
.
</a>
</p>
<table class="css-11h39yh e1nex8bq0">
<colgroup>
<col class="field-name"/>
<col class="field-body"/>
</colgroup>
<tbody>
<tr class="css-x8snli">
<th>
Returns
<!-- -->
:
</th>
<td>
This method returns a cursor with a
<code class="leafygreen-ui-1l06pbn">
documents
</code>
array,
which contains a document for each inconsistency found in
the sharding metadata.
</td>
</tr>
</tbody>
</table>
</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-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-method-db.collection.checkMetadataConsistency" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.checkMetadataConsistency()
</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.collection.checkMetadataConsistency( { <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-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">checkMetadataConsistency</span>( <!-- -->{ <<!-- -->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">
options
</code>
document can take 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:15%"/>
<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">
checkIndexes
</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">
Sets whether the command also checks indexes in sharding metadata.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, this operation is disabled, because if it can return false
positives inconsistencies when run concurrent with operations that
create, delete, or modify indexes. Only check indexes at times when
you know these operations are unlikely to occur.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<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>
Configures the return cursor.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
cursor.batchSize
</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>
Maximum number of sharding metadata inconsistency documents
to include in each batch.
</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 class="css-1f5771r">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.authors.checkMetadataConsistency()","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">authors</span>.<span class="lg-highlight-title lg-highlight-function">checkMetadataConsistency</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 cursorHasMore: false,\n documents: [\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}","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"> cursorHasMore<span class="lg-highlight-punctuation">:</span> <span class="lg-highlight-keyword">false</span><span class="lg-highlight-punctuation">,</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> documents<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></td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/getCmdLineOpts/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
getCmdLineOpts
<a class="headerlink leafygreen-ui-1kepx47" href="#getcmdlineopts" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="getcmdlineopts">
</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="#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">
getCmdLineOpts
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.getCmdLineOpts" 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.getCmdLineOpts">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getCmdLineOpts" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getCmdLineOpts
</code>
</span>
</a>
command returns a document
containing command line options used to start the given
<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>
. Run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getCmdLineOpts" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getCmdLineOpts
</code>
</span>
</a>
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-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 getCmdLineOpts: 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-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">getCmdLineOpts</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>
<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">
This command returns a document with two fields,
<code class="leafygreen-ui-1l06pbn">
argv
</code>
and
<code class="leafygreen-ui-1l06pbn">
parsed
</code>
. The
<code class="leafygreen-ui-1l06pbn">
argv
</code>
field contains an array with each item from
the command string used to invoke
<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>
. The document in the
<code class="leafygreen-ui-1l06pbn">
parsed
</code>
field includes all
runtime options, including those parsed from the command line and
those specified in the configuration file, if specified.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following example output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.getCmdLineOpts" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
getCmdLineOpts
</code>
:
</span>
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"argv\" : [\n \"/usr/bin/mongod\",\n \"--config\",\n \"/etc/mongod.conf\"\n ],\n \"parsed\" : {\n \"config\" : \"/etc/mongod.conf\",\n \"net\" : {\n \"bindIp\" : \"127.0.0.1\",\n \"port\" : 27017\n },\n \"processManagement\" : {\n \"fork\" : true\n },\n \"storage\" : {\n \"dbPath\" : \"/data/db\"\n },\n \"systemLog\" : {\n \"destination\" : \"file\",\n \"logAppend\" : true,\n \"path\" : \"/var/log/mongodb/mongod.log\"\n }\n },\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">"argv"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"/usr/bin/mongod"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"--config"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"/etc/mongod.conf"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"parsed"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"config"</span> <!-- -->: <span class="lg-highlight-string">"/etc/mongod.conf"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"net"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"bindIp"</span> <!-- -->: <span class="lg-highlight-string">"127.0.0.1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"port"</span> <!-- -->: <span class="lg-highlight-number">27017</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"processManagement"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"fork"</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-string">"storage"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"dbPath"</span> <!-- -->: <span class="lg-highlight-string">"/data/db"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"systemLog"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"destination"</span> <!-- -->: <span class="lg-highlight-string">"file"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"logAppend"</span> <!-- -->: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"path"</span> <!-- -->: <span class="lg-highlight-string">"/var/log/mongodb/mongod.log"</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">"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>
|
https://www.mongodb.com/docs/manual/reference/method/sh.addTagRange/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
sh.addTagRange()
<a class="headerlink leafygreen-ui-1kepx47" href="#sh.addtagrange--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.addtagrange--">
</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="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange(namespace, minimum, maximum, tag)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-sh.addTagRange" 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.addTagRange">
</div>
</a>
</dt>
<dd>
<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 method aliases to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</a>
. MongoDB provides
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
Zone sharding
</a>
as the successor to tag-aware sharding.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Attaches a range of shard key values to a shard tag created using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag">
<code class="leafygreen-ui-1l06pbn">
sh.addShardTag()
</code>
</a>
method.
</p>
<p class="leafygreen-ui-1kp3ins">
You can run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/updateZoneKeyRange/#mongodb-dbcommand-dbcmd.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</a>
database command and its helpers
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</span>
</a>
on
an unsharded collection or a non-existing collection.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</span>
</a>
takes
the following arguments:
</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">
namespace
</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 sharded collection to tag.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
minimum
</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 minimum value of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
range to include in the
tag. The minimum is an inclusive match. Specify the minimum value in
the form of
<code class="leafygreen-ui-1l06pbn">
<fieldname>:<value>
</code>
. This value must be of the same
BSON type or types as the shard key.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
maximum
</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 maximum value of the shard key range to include in the tag.
The maximum is an exclusive match. Specify the maximum value in the
form of
<code class="leafygreen-ui-1l06pbn">
<fieldname>:<value>
</code>
. This value must be of the same BSON
type or types as the shard key.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
tag
</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 tag to attach the range specified by the
<code class="leafygreen-ui-1l06pbn">
minimum
</code>
and
<code class="leafygreen-ui-1l06pbn">
maximum
</code>
arguments to.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShardTag/#mongodb-method-sh.addShardTag">
<code class="leafygreen-ui-1l06pbn">
sh.addShardTag()
</code>
</a>
to ensure that the balancer migrates
documents that exist within the specified range to a specific shard
or set of shards.
</p>
<p class="leafygreen-ui-1kp3ins">
Only issue
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</span>
</a>
when connected 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.
</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">
Bounds
<a class="headerlink leafygreen-ui-1kepx47" href="#bounds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="bounds">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Zone ranges are always inclusive of the lower boundary and exclusive
of the upper boundary.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-addTagRange-method-init-chunk-distribution">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initial Chunk Distribution for Empty or Non-Existing Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-for-empty-or-non-existing-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="initial-chunk-distribution-for-empty-or-non-existing-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you are considering performing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zone sharding
</a>
on an empty or non-existent collection, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-sh.addTagRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</span>
</a>
to create the zones and zone ranges
<em>
before
</em>
sharding the collection.
Creating zones and zone ranges on empty or non-existing collections allows
MongoDB to optimize the initial chunk creation and distribution process when
sharding the collection. This optimized process supports faster setup of zoned
sharding with less balancer overhead than creating zones after sharding. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
performs all chunk management after the
optimized initial chunk creation and distribution.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example of defining zones and zone ranges for initial chunk
distribution, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</a>
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Initial Chunk Distribution with Compound Hashed Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-with-compound-hashed-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="initial-chunk-distribution-with-compound-hashed-shard-keys">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports sharding collections on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
compound hashed indexes
</a>
. MongoDB can
perform optimized initial chunk creation and distribution when sharding
the empty or non-existing collection on a compound hashed shard key.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-10">
<div aria-label="Tabs to describe usage of hash-not-prefix/hash-prefix" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_x8xi1n3n4" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_rj8k7nuw5" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field Is Prefix
</div>
</button>
<button aria-controls="_vd85ks8e8" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_vekhwjfu6" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field is Not Prefix
</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="_bpiajo6nr" class="" id="_ipbxcibuw" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is the prefix of the shard key (i.e. the first
field in the shard key), all of the following must be true for
MongoDB to perform initial chunk creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has a single zone range with
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
all lower-bound fields and
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
for all upper-bound
fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
<div>
<div aria-labelledby="_yi2t90nxx" class="leafygreen-ui-38lglc" id="_01rfg1qw8" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is
<em>
not
</em>
the prefix of the shard key (i.e.
the shard key has one or more non-hashed leading fields), all of
the following must be true for MongoDB to perform initial chunk
creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has one zone range for each combination of distinct
prefix field values (i.e. all fields preceding the hashed field).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the lower-bound of each zone range, specify
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
the hashed field and all subsequent fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For each zone range, at least one upper-bound prefix field
<em>
must
</em>
differ from its lower-bound counterpart.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For a more complete example of defining zones and zone ranges for
initial chunk distribution on a compound hashed shard key, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Dropped Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#dropped-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">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Dropping a collection deletes its associated zone/tag ranges.
</p>
<p class="leafygreen-ui-1kp3ins">
In earlier versions, MongoDB does not remove the tag associations for a
dropped collection, and if you later create a new collection with the
same name, the old tag associations will apply to the new collection.
</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">
Given a shard key of
<code class="leafygreen-ui-1l06pbn">
{state: 1, zip: 1}
</code>
, the following operation
creates a tag range covering zip codes in New York State:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addTagRange( \"exampledb.collection\",\n { state: \"NY\", zip: MinKey },\n { state: \"NY\", zip: MaxKey },\n \"NY\"\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">sh.<span class="lg-highlight-title lg-highlight-function">addTagRange</span>( <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"NY"</span>, <span class="lg-highlight-attr">zip</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">state</span>: <span class="lg-highlight-string">"NY"</span>, <span class="lg-highlight-attr">zip</span>: <span class="lg-highlight-title lg-highlight-class">MaxKey</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"NY"</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/change-oplog-size/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Change the Oplog Size of Self-Managed Replica Set Members
<a class="headerlink leafygreen-ui-1kepx47" href="#change-the-oplog-size-of-self-managed-replica-set-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="change-the-oplog-size-of-self-managed-replica-set-members">
</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="#a.-connect-to-the-replica-set-member" target="_self">
<span>
A. Connect to the replica set member
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#b.--optional--verify-the-current-size-of-the-oplog" target="_self">
<span>
B. (Optional) Verify the current size of the oplog
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#c.-change-the-oplog-size-of-the-replica-set-member" target="_self">
<span>
C. Change the oplog size of the replica set member
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#d.--optional--compact-oplog.rs-to-reclaim-disk-space" target="_self">
<span>
D. (Optional) Compact
<code class="css-1kekw28 e1wawog0">
oplog.rs
</code>
to reclaim disk space
</span>
</a>
</li>
</ul>
</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">
You cannot drop the
<code class="leafygreen-ui-1l06pbn">
local.oplog.rs
</code>
collection. For more information on
this restriction, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-oplog-coll-behavior">
Oplog Collection Behavior
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This procedure changes the size of the oplog
<a class="footnote-reference header-buffer" href="#footnote-oplog" id="ref-oplog-id1">
[
<!-- -->
1
<!-- -->
]
</a>
on each member of a
replica set using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
command, starting
with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members before proceeding to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Perform these steps on each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
replica set member
<em>
first
</em>
. Once you have changed the oplog size for all secondary
members, perform these steps on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
A. Connect to the replica set member
<a class="headerlink leafygreen-ui-1kepx47" href="#a.-connect-to-the-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="a.-connect-to-the-replica-set-member">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Connect to the replica set member 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>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --host <hostname>:<port>","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 --host <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 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 replica set enforces
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication
</a>
,
you must authenticate as a user with privileges to modify the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database, such as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
<code class="leafygreen-ui-1l06pbn">
clusterManager
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
role.
</p>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
B. (Optional) Verify the current size of the oplog
<a class="headerlink leafygreen-ui-1kepx47" href="#b.--optional--verify-the-current-size-of-the-oplog" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="b.--optional--verify-the-current-size-of-the-oplog">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To view the current size of the oplog, switch to the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database and run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
against the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
stats()
</code>
</a>
displays the
oplog size as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.maxSize">
<code class="leafygreen-ui-1l06pbn">
maxSize
</code>
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use local\ndb.oplog.rs.stats().maxSize","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 local</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">oplog</span>.<span class="lg-highlight-property">rs</span>.<span class="lg-highlight-title lg-highlight-function">stats</span>(<!-- -->).<span class="lg-highlight-property">maxSize</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">
maxSize
</code>
field displays the collection size in bytes.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
C. Change the oplog size of the replica set member
<a class="headerlink leafygreen-ui-1kepx47" href="#c.-change-the-oplog-size-of-the-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="c.-change-the-oplog-size-of-the-replica-set-member">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Resize the oplog with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetResizeOplog/#mongodb-dbcommand-dbcmd.replSetResizeOplog">
<code class="leafygreen-ui-1l06pbn">
replSetResizeOplog
</code>
</a>
command. The
<code class="leafygreen-ui-1l06pbn">
size
</code>
is a double and must be greater than
<code class="leafygreen-ui-1l06pbn">
990
</code>
megabytes. To
explicitly cast the oplog
<code class="leafygreen-ui-1l06pbn">
size
</code>
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>
, use the
<code class="leafygreen-ui-1l06pbn">
Double()
</code>
constructor.
</p>
<p class="leafygreen-ui-1kp3ins">
The following operation changes the oplog size of the replica set
member to 16 gigabytes, or 16000 megabytes.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand({replSetResizeOplog: 1, size: Double(16000)})","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">replSetResizeOplog</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">size</span>: <span class="lg-highlight-title lg-highlight-class">Double</span>(<span class="lg-highlight-number">16000</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>
<table class="header-buffer leafygreen-ui-rbqgrl" frame="void" id="footnote-oplog" rules="none">
<colgroup>
<col/>
</colgroup>
<tbody valign="top">
<tr>
<td class="leafygreen-ui-17r2xs0">
[
<a href="#ref-oplog-id1">
1
</a>
]
</td>
<td class="leafygreen-ui-17r2xs0">
<!-- -->
The oplog can grow past its configured size
limit to avoid deleting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
<code class="leafygreen-ui-1l06pbn">
majority commit point
</code>
.
</a>
</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
D. (Optional) Compact
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
to reclaim disk space
<a class="headerlink leafygreen-ui-1kepx47" href="#d.--optional--compact-oplog.rs-to-reclaim-disk-space" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="d.--optional--compact-oplog.rs-to-reclaim-disk-space">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Reducing the size of the oplog does
<em>
not
</em>
automatically reclaim
the disk space allocated to the original oplog size. You must run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#mongodb-dbcommand-dbcmd.compact">
<code class="leafygreen-ui-1l06pbn">
compact
</code>
</a>
against the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection in the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database to reclaim disk space. There are no benefits to
running
<code class="leafygreen-ui-1l06pbn">
compact
</code>
on the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection after increasing the
oplog size.
</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 replica set member can replicate oplog entries while the
<code class="leafygreen-ui-1l06pbn">
compact
</code>
operation is ongoing. As a result, it is no longer necessary to limit
compaction operations on the oplog to maintenance windows, as oplog
replication can continue as normal during compaction.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Do
<strong>
not
</strong>
run
<code class="leafygreen-ui-1l06pbn">
compact
</code>
against the primary replica set member.
Connect a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
</a>
shell directly to the primary
(not the replica set) and run
<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>
. If successful,
the primary steps down. From the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongo/#mongodb-binary-bin.mongo">
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
</a>
shell, run
the
<code class="leafygreen-ui-1l06pbn">
compact
</code>
command on the now-secondary member.
</p>
<p class="leafygreen-ui-1kp3ins">
The following operation runs the
<code class="leafygreen-ui-1l06pbn">
compact
</code>
command against the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use local\ndb.runCommand({ \"compact\" : \"oplog.rs\" } )","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 local</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-title lg-highlight-function">runCommand</span>(<!-- -->{ <span class="lg-highlight-string">"compact"</span> <!-- -->: <span class="lg-highlight-string">"oplog.rs"</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 clusters enforcing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication
</a>
,
authenticate as a user with the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-compact">
<code class="leafygreen-ui-1l06pbn">
compact
</code>
</a>
privilege
action on the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database and the
<code class="leafygreen-ui-1l06pbn">
oplog.rs
</code>
collection.
For complete documentation on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#mongodb-dbcommand-dbcmd.compact">
<code class="leafygreen-ui-1l06pbn">
compact
</code>
</a>
authentication
requirements, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/compact/#std-label-compact-authentication">
<code class="leafygreen-ui-1l06pbn">
compact
</code>
Required Privileges
<!-- -->
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/sharding-balancer-administration/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Sharded Cluster Balancer
<a class="headerlink leafygreen-ui-1kepx47" href="#sharded-cluster-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="sharded-cluster-balancer">
</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="#balancer-internals" target="_self">
<span>
Balancer Internals
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#range-migration-procedure" target="_self">
<span>
Range Migration Procedure
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#shard-size" target="_self">
<span>
Shard Size
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#chunk-size-and-balancing" target="_self">
<span>
Chunk Size and Balancing
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
The MongoDB balancer is a background process that monitors the amount of
data on each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
for each sharded collection. When the amount
of data for a sharded collection on a given shard reaches specific
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-migration-thresholds" target="_self">
<span>
migration thresholds
</span>
</a>
, the balancer
attempts to automatically migrate data between shards and reach an even
amount of data per shard while respecting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zones
</a>
. By default, the balancer process is always enabled.
</p>
<p class="leafygreen-ui-1kp3ins">
The balancing procedure for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded clusters
</a>
is entirely transparent to the user and application layer, though there
may be some performance impact while the procedure takes place.
</p>
<div class="figure css-5vkxs0" style="width:700px">
<img alt="Diagram of a collection distributed across three shards. For this collection, the difference in the number of chunks between the shards reaches the *migration thresholds* (in this case, 2) and triggers migration." class="leafygreen-ui-1qnf57e" height="180" src="/docs/manual/images/sharding-migrating.bakedsvg.svg" style="--border-color:#C1C7C6" width="500"/>
</div>
<p class="leafygreen-ui-1kp3ins">
The balancer runs on the primary of the config server replica set
(CSRS).
</p>
<p class="leafygreen-ui-1kp3ins">
To configure collection balancing for a single collection, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/configureCollectionBalancing/#mongodb-dbcommand-dbcmd.configureCollectionBalancing">
<code class="leafygreen-ui-1l06pbn">
configureCollectionBalancing
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To manage the sharded cluster balancer, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharded-cluster-balancer">
Manage Sharded Cluster Balancer
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-balancing-internals">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-internals-balancing">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Balancer Internals
<a class="headerlink leafygreen-ui-1kepx47" href="#balancer-internals" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="balancer-internals">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Range migrations carry some overhead in terms of bandwidth and
workload, both of which can impact database performance.
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-balancer">
balancer
</a>
attempts to minimize the impact by:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Restricting a shard to at most one migration at any given time.
Specifically, a shard cannot participate in multiple data migrations
at the same time. The balancer migrates ranges one at a time.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB can perform parallel data migrations, but a shard can
participate in at most one migration at a time. For a sharded cluster
with
<em>
n
</em>
shards, MongoDB can perform at most
<em>
n/2
</em>
(rounded down)
simultaneous migrations.
</p>
<p class="leafygreen-ui-1kp3ins">
See also
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-range-migration-queuing" target="_self">
<span>
Asynchronous Range Migration Cleanup
<!-- -->
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting a balancing round only when the
<strong>
difference in the amount
of data
</strong>
between the shard with the most data for a sharded collection
and the shard with the least data for that collection reaches the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sharding-migration-thresholds" target="_self">
<span>
migration threshold
<!-- -->
.
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You can disable the balancer temporarily for maintenance, but leaving
the balancer disabled for extended periods of time can degrade cluster
performance. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-balancing-disable-temporally">
Disable the Balancer
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can also limit the window during which the balancer runs to prevent
it from impacting production traffic. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-schedule-balancing-window">
Schedule the Balancing
Window
</a>
for details.
</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 specification of the balancing window is relative to the local
time zone of the primary of the config server replica set.
</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/manage-sharded-cluster-balancer/#std-label-sharded-cluster-balancer">
Manage Sharded Cluster Balancer
</a>
</p>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Adding and Removing Shards from the Cluster
<a class="headerlink leafygreen-ui-1kepx47" href="#adding-and-removing-shards-from-the-cluster" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="adding-and-removing-shards-from-the-cluster">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Adding a shard to a cluster creates an imbalance, since the new
shard has no data. While MongoDB begins migrating data to the new
shard immediately, it can take some time before the cluster balances.
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/add-shards-to-shard-cluster/#std-label-sharding-procedure-add-shard">
Add Shards to a Cluster
</a>
tutorial for instructions on adding a shard to a cluster.
</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">
If your application meets the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-reshard-a-collection/#std-label-reshard-requirements">
Before you Begin
</a>
, you can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/reshardCollection/#mongodb-dbcommand-dbcmd.reshardCollection">
<code class="leafygreen-ui-1l06pbn">
reshardCollection
</code>
</a>
command to redistribute data across the
cluster to include the new shards. This process is much faster than the
alternative
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-range-migration-procedure" target="_self">
<span>
Range Migration Procedure
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For an example, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/reshardCollection/#std-label-reshardCollection-redistribute-data">
Redistribute Data to New Shards
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Removing a shard from a cluster creates a similar imbalance, since data
residing on that shard must be redistributed throughout the cluster.
While MongoDB begins draining a removed shard immediately, it can take
some time before the cluster balances.
<em>
Do not
</em>
shutdown the servers
associated to the removed shard during this process.
</p>
<p class="leafygreen-ui-1kp3ins">
When you remove a shard in a cluster with an uneven chunk
distribution, the balancer first removes the chunks from the draining
shard and then balances the remaining uneven chunk distribution.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/remove-shards-from-cluster/#std-label-remove-shards-from-cluster-tutorial">
Remove Shards from a Cluster
</a>
tutorial for instructions on
safely removing a shard from a cluster.
</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/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
<code class="leafygreen-ui-1l06pbn">
sh.balancerCollectionStatus()
</code>
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-chunk-migration-procedure">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-range-migration-procedure">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Range Migration Procedure
<a class="headerlink leafygreen-ui-1kepx47" href="#range-migration-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="range-migration-procedure">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
All range migrations use the following procedure:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The balancer process sends the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
command to
the source shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The source starts the move when it receives an internal
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
command. During the migration process,
operations to the range are sent to the source shard. The source
shard is responsible for incoming write operations for the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The destination shard builds any indexes required by the source
that do not exist on the destination.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The destination shard begins requesting documents in the range and
starts receiving copies of the data. See also
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-range-migration-replication" target="_self">
<span>
Range Migration and Replication
<!-- -->
.
</span>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
After receiving the final document in the range, the
destination shard starts a synchronization process to ensure that it
has the changes to the migrated documents that occurred during the
migration.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When fully synchronized, the source shard connects to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-config-database">
config database
</a>
and updates the cluster metadata with the new
location for the range.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
After the source shard completes the update of the metadata,
and once there are no open cursors on the range, the source shard
deletes its copy of the documents.
</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 balancer needs to perform additional chunk migrations from
the source shard, the balancer can start the next chunk migration
without waiting for the current migration process to finish this
deletion step. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-chunk-migration-queuing" target="_self">
<span>
Asynchronous Range Migration Cleanup
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</li>
</ol>
<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>
<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/serverStatus/#mongodb-serverstatus-serverstatus.shardingStatistics.countDonorMoveChunkLockTimeout">
<code class="leafygreen-ui-1l06pbn">
shardingStatistics.countDonorMoveChunkLockTimeout
</code>
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-migration-thresholds">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Migration Thresholds
<a class="headerlink leafygreen-ui-1kepx47" href="#migration-thresholds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="migration-thresholds">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To minimize the impact of balancing on the cluster, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-balancer">
balancer
</a>
only begins balancing after the distribution of
data for a sharded collection has reached certain thresholds.
</p>
<p class="leafygreen-ui-1kp3ins">
A collection is considered balanced if the difference in data between
shards (for that collection) is less than three times the configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/modify-chunk-size-in-sharded-cluster/#std-label-tutorial-modifying-range-size">
range size
</a>
for the collection.
For the default range size of
<code class="leafygreen-ui-1l06pbn">
128MB
</code>
, two shards must have a data
size difference for a given collection of at least
<code class="leafygreen-ui-1l06pbn">
384MB
</code>
for a
migration to occur.
</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/method/sh.balancerCollectionStatus/#mongodb-method-sh.balancerCollectionStatus">
<code class="leafygreen-ui-1l06pbn">
sh.balancerCollectionStatus()
</code>
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-chunk-migration-queuing">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-range-migration-queuing">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-asynchronous-chunk-migration-cleanup">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Asynchronous Range Migration Cleanup
<a class="headerlink leafygreen-ui-1kepx47" href="#asynchronous-range-migration-cleanup" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="asynchronous-range-migration-cleanup">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To migrate data from a shard, the balancer migrates the
data one range at a time. However, the balancer does not wait for the
current migration's delete phase to complete before starting the next
range migration. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-range-migration">
Range Migration
</a>
for the range
migration process and the delete phase.
</p>
<p class="leafygreen-ui-1kp3ins">
This queuing behavior allows shards to unload data more quickly in
cases of heavily imbalanced cluster, such as when performing initial
data loads without pre-splitting and when adding new shards.
</p>
<p class="leafygreen-ui-1kp3ins">
This behavior also affects the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
command, and
migration scripts that use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
command may
proceed more quickly.
</p>
<p class="leafygreen-ui-1kp3ins">
In some cases, the delete phases may persist longer. Range migrations
are enhanced to be more resilient in the event of a failover during the
delete phase. Orphaned documents are cleaned up even if a replica set's
primary crashes or restarts during this phase.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_waitForDelete
</code>
balancer setting can alter the behavior so that
the delete phase of the current migration blocks the start of the next
chunk migration. The
<code class="leafygreen-ui-1l06pbn">
_waitForDelete
</code>
is generally for internal
testing purposes. For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-wait-for-delete-setting">
Wait for Delete
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-chunk-migration-replication">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-range-migration-replication">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Range Migration and Replication
<a class="headerlink leafygreen-ui-1kepx47" href="#range-migration-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="range-migration-and-replication">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
During range migration, the
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
value determines
when the migration proceeds with next document in the range.
</p>
<p class="leafygreen-ui-1kp3ins">
In the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#mongodb-data-config.settings">
<code class="leafygreen-ui-1l06pbn">
config.settings
</code>
</a>
collection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
setting for the balancer is set to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-write-concern">
write concern
</a>
, each document moved during range migration must receive
the requested acknowledgment before proceeding with the next
document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
setting is unset, the migration process
does not wait for replication to a secondary and instead continues
with the next document.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To update the
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
parameter for the balancer, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharded-cluster-config-secondary-throttle">
Secondary Throttle
</a>
for an example.
</p>
<p class="leafygreen-ui-1kp3ins">
Independent of any
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
setting, certain phases of
the range migration have the following replication policy:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB briefly pauses all application reads and writes to the
collection being migrated to on the source shard before updating the
config servers with the range location. MongoDB resumes application
reads and writes after the update. The range move requires all writes
to be acknowledged by majority of the members of the replica set both
before and after committing the range move to config servers.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When an outgoing migration finishes and cleanup occurs, all
writes must be replicated to a majority of servers before further
cleanup (from other outgoing migrations) or new incoming migrations
can proceed.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To update the
<code class="leafygreen-ui-1l06pbn">
_secondaryThrottle
</code>
setting in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/config-database/#mongodb-data-config.settings">
<code class="leafygreen-ui-1l06pbn">
config.settings
</code>
</a>
collection, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharded-cluster-config-secondary-throttle">
Secondary Throttle
</a>
for an example.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-migration-chunk-size-limit">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-migration-range-size-limit">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Maximum Number of Documents Per Range to Migrate
<a class="headerlink leafygreen-ui-1kepx47" href="#maximum-number-of-documents-per-range-to-migrate" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="maximum-number-of-documents-per-range-to-migrate">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, MongoDB cannot move a range if the number of documents in
the range is greater than 2 times the result of dividing the
configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-sharding-range-size">
range size
</a>
by the average
document size. If MongoDB can move a sub-range of a chunk and reduce the
size to less than that, the balancer does so by migrating a range.
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
includes the
<code class="leafygreen-ui-1l06pbn">
avgObjSize
</code>
field,
which represents the average document size in the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
For chunks that are
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-migration-chunk-size-limit" target="_self">
<span>
too large to migrate
<!-- -->
:
</span>
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The balancer setting
<code class="leafygreen-ui-1l06pbn">
attemptToBalanceJumboChunks
</code>
allows the
balancer to migrate chunks too large to move as long as the chunks
are not labeled
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-jumbo-chunk">
jumbo
</a>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-balance-chunks-that-exceed-size-limit">
Balance Ranges that Exceed Size Limit
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
When issuing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#mongodb-dbcommand-dbcmd.moveRange">
<code class="leafygreen-ui-1l06pbn">
moveRange
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveChunk/#mongodb-dbcommand-dbcmd.moveChunk">
<code class="leafygreen-ui-1l06pbn">
moveChunk
</code>
</a>
commands, it's possible to specify the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/moveRange/#std-label-moverange-forceJumbo">
forceJumbo
</a>
option to allow for the migration of ranges
that are too large to move. The ranges may or may not be labeled
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-data-partitioning/#std-label-jumbo-chunk">
jumbo
<!-- -->
.
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-range-deletion-performance-tuning">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Range Deletion Performance Tuning
<a class="headerlink leafygreen-ui-1kepx47" href="#range-deletion-performance-tuning" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="range-deletion-performance-tuning">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You can tune the performance impact of range deletions
with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterBatchSize">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterBatchSize
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterBatchDelayMS">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterBatchDelayMS
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterHighPriority">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterHighPriority
</code>
</a>
parameters. For example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To limit the number of documents deleted per batch, you can set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterBatchSize">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterBatchSize
</code>
</a>
to a small value such as
<code class="leafygreen-ui-1l06pbn">
32
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To add an additional delay between batch deletions, you can set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterBatchDelayMS">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterBatchDelayMS
</code>
</a>
above the current default of
<code class="leafygreen-ui-1l06pbn">
20
</code>
milliseconds.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To prioritize range deletions, you can set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.rangeDeleterHighPriority">
<code class="leafygreen-ui-1l06pbn">
rangeDeleterHighPriority
</code>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
. Range deletions
are potentially long-running background tasks that might negatively impact
the throughput of user operations when the system is under heavy load.
</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">
If there are ongoing read operations or open cursors on the
collection targeted for deletes, range deletion processes may
not proceed.
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change Streams and Orphan Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#change-streams-and-orphan-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="change-streams-and-orphan-documents">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.3, during
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-range-migration-procedure" target="_self">
<span>
range migration
</span>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change stream
</a>
events are not generated for updates to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sharding-shard-size">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Shard Size
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-size" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-size">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
By default, MongoDB attempts to fill all available disk space with
data on every shard as the data set grows. To ensure that the cluster
always has the capacity to handle data growth, monitor disk
usage as well as other performance metrics.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharded-cluster-config-max-shard-size">
Change the Maximum Storage Size for a Given Shard
</a>
tutorial for
instructions on setting the maximum size for a shard.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Chunk Size and Balancing
<a class="headerlink leafygreen-ui-1kepx47" href="#chunk-size-and-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="chunk-size-and-balancing">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For an introduction to
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/modify-chunk-size-in-sharded-cluster/#std-label-tutorial-modifying-chunk-size">
Modify Range Size in a Sharded Cluster
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The following table describes how
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
affects defragmentation
and the balancer operations in different MongoDB versions.
</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>
MongoDB 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>
MongoDB 6.0 and later
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
When the collection data shared between two shards differs by
three or more times the configured
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
setting, the
balancer migrates chunks between the shards.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, if
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
is 128 MB and the collection data
differs by 384 MB or more, the balancer migrates chunks between
the shards.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Earlier than MongoDB 6.0
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
When a chunk grows larger than
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
, the chunk is split.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
When chunks are moved, split, or merged, the shard metadata is updated
after the chunk operation is committed by a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharded-cluster-config-servers/#std-label-sharding-config-server">
config server
</a>
. Shards not involved in the chunk operation
are also updated with new metadata.
</p>
<p class="leafygreen-ui-1kp3ins">
The time for the shard metadata update is proportional to the size of
the routing table. CRUD operations on the collection are temporarily
blocked while the shard metadata is updated, and a smaller routing table
means shorter CRUD operation delays.
</p>
<p class="leafygreen-ui-1kp3ins">
Defragmenting a collection reduces the number of chunks and the time to
update the chunk metadata.
</p>
<p class="leafygreen-ui-1kp3ins">
To reduce the system workload, configure the balancer to run only at a
specific time using a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-sharded-cluster-balancer/#std-label-sharding-schedule-balancing-window">
shard balancing window
</a>
. Defragmentation runs during the
balancing window time period.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.chunkDefragmentationThrottlingMS">
<code class="leafygreen-ui-1l06pbn">
chunkDefragmentationThrottlingMS
</code>
</a>
parameter
to limit the rate of split and merge commands run by the balancer.
</p>
<p class="leafygreen-ui-1kp3ins">
You can start and stop defragmentation at any time.
</p>
<p class="leafygreen-ui-1kp3ins">
You can also set a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
shard zone
</a>
. A shard zone is
based on the shard key, and you can associate each zone with one or more
shards in a cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.0, a sharded cluster only splits chunks when
chunks must be migrated. This means the chunk size may exceed
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
. Larger chunks reduce the number of chunks on a shard and
improve performance because the time to update the shard metadata is
reduced. For example, you might see a 1 TB chunk on a shard even though
you have set
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
to 256 MB.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
chunkSize
</code>
affects the following:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Maximum amount of data the balancer attempts to migrate between two
shards in a single chunk migration operation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Amount of data migrated during defragmentation.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For details about defragmenting sharded collections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/defragment-sharded-collections/#std-label-defragment-sharded-collections">
Defragment Sharded Collections
<!-- -->
.
</a>
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/add-shards-to-shard-cluster/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Add Shards to a Cluster
<a class="headerlink leafygreen-ui-1kepx47" href="#add-shards-to-a-cluster" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-shards-to-a-cluster">
</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="#considerations" target="_self">
<span>
Considerations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#add-a-shard-to-a-cluster" target="_self">
<span>
Add a Shard to a Cluster
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
You add shards to a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
after you create the cluster
or any time that you need to add capacity to the cluster. If you have not
created a sharded cluster, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/deploy-shard-cluster/#std-label-sharding-procedure-setup">
Deploy a Self-Managed Sharded Cluster
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
All shards must be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica sets
<!-- -->
.
</a>
</p>
<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">
Capacity Planning
<a class="headerlink leafygreen-ui-1kepx47" href="#capacity-planning" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="capacity-planning">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When adding a shard to a cluster, always ensure that the cluster has
enough capacity to support the migration required for balancing the
cluster without affecting legitimate production traffic.
</p>
</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 add a shard 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>
), the operation that adds a shard only
executes after the concurrent DDL operation finishes.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Add a Shard to a Cluster
<a class="headerlink leafygreen-ui-1kepx47" href="#add-a-shard-to-a-cluster" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-shard-to-a-cluster">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You interact with a sharded cluster by connecting 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.
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<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>
, connect to 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. For example, if a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
is accessible at
<code class="leafygreen-ui-1l06pbn">
mongos0.example.net
</code>
on port
<code class="leafygreen-ui-1l06pbn">
27017
</code>
, issue the following
command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --host mongos0.example.net --port 27017","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 --host mongos0.example.net --port 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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add a shard replica set to the cluster using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShard/#mongodb-method-sh.addShard">
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</a>
method, as shown in the example below. Issue
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShard/#mongodb-method-sh.addShard">
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
</a>
separately for each shard. Specify the name of the replica set and a
member of the set.
</p>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Optional
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
You can instead use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShard/#mongodb-dbcommand-dbcmd.addShard">
<code class="leafygreen-ui-1l06pbn">
addShard
</code>
</a>
database
command, which lets you specify a name and maximum size for the
shard. If you do not specify these, MongoDB automatically assigns
a name and maximum size. To use the database command, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShard/#mongodb-dbcommand-dbcmd.addShard">
<code class="leafygreen-ui-1l06pbn">
addShard
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The following example illustrates adding a shard with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addShard/#mongodb-method-sh.addShard">
<code class="leafygreen-ui-1l06pbn">
sh.addShard()
</code>
:
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To add a shard replica set named
<code class="leafygreen-ui-1l06pbn">
rs1
</code>
with a member
running on port
<code class="leafygreen-ui-1l06pbn">
27018
</code>
on
<code class="leafygreen-ui-1l06pbn">
mongodb0.example.net
</code>
, issue the
following command:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"sh.addShard( \"rs1/mongodb0.example.net:27018\" )","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">"rs1/mongodb0.example.net:27018"</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">
It might take some time for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunks
</a>
to
migrate to the new shard.
</p>
</div>
</div>
</li>
</ol>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-granularity/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Set Granularity for Time Series Data
<a class="headerlink leafygreen-ui-1kepx47" href="#set-granularity-for-time-series-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="set-granularity-for-time-series-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="#retrieve-the-current-bucketing-parameters" target="_self">
<span>
Retrieve the Current Bucketing Parameters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#set-the--granularity--parameter" target="_self">
<span>
Set the "granularity" Parameter
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#using-custom-bucketing-parameters" target="_self">
<span>
Using Custom Bucketing Parameters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#change-time-series-granularity" target="_self">
<span>
Change Time Series Granularity
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
When you create a time series collection, MongoDB automatically creates
a
<code class="leafygreen-ui-1l06pbn">
system.buckets
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/system-collections/#std-label-metadata-system-collections">
system collection
</a>
and groups incoming time series data
into buckets. By setting granularity, you control how
frequently data is bucketed based on the ingestion rate of your data.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.3, you can use the custom bucketing parameters
<code class="leafygreen-ui-1l06pbn">
bucketMaxSpanSeconds
</code>
and
<code class="leafygreen-ui-1l06pbn">
bucketRoundingSeconds
</code>
to specify bucket
boundaries and more accurately control how time series data is bucketed.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on bucketing, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-bucketing/#std-label-timeseries-bucketing">
About Time Series Data
<!-- -->
.
</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">
You must be running MongoDB 5.0.1 or later in order to change a
time series collection's granularity after the collection has been
created. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/release-notes/5.0/#std-label-5.0-known-issue-granularity">
MongoDB 5.0 known issues
<!-- -->
.
</a>
</p>
</div>
</div>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Retrieve the Current Bucketing Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#retrieve-the-current-bucketing-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-the-current-bucketing-parameters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To retrieve current collection values, 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">
For time series collections, the output contains
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
,
<code class="leafygreen-ui-1l06pbn">
bucketMaxSpanSeconds
</code>
, and
<code class="leafygreen-ui-1l06pbn">
bucketRoundingSeconds
</code>
parameters, if
present.
</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 timeField: <string>,\n metaField: <string>,\n granularity: <string>,\n bucketMaxSpanSeconds: <number>,\n bucketRoundingSeconds: <number>\n }\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"> <span class="lg-highlight-attr">timeField</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaField</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">granularity</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bucketMaxSpanSeconds</span>: <<!-- -->number<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bucketRoundingSeconds</span>: <<!-- -->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"> }<!-- -->,</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">
Set the "granularity" Parameter
<a class="headerlink leafygreen-ui-1kepx47" href="#set-the--granularity--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="set-the--granularity--parameter">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The following example sets the
<code class="leafygreen-ui-1l06pbn">
granuarity
</code>
of a
<code class="leafygreen-ui-1l06pbn">
weather24h
</code>
collection to
<code class="leafygreen-ui-1l06pbn">
hours
</code>
:
</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: \"minutes\"\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">"minutes"</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>
<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/timeseries/timeseries-automatic-removal/#std-label-timeseries-collection-delete-operations-timing">
Timing of Automatic Removal
</a>
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-flexible-bucketing">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Using Custom Bucketing Parameters
<a class="headerlink leafygreen-ui-1kepx47" href="#using-custom-bucketing-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="using-custom-bucketing-parameters">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In MongoDB 6.3 and higher, instead of
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
, you can set
bucket boundaries manually using the two custom bucketing parameters.
Consider this approach if you expect to query data for fixed time
intervals, such as every 4 hours starting at midnight. Ensuring buckets
don't overlap between those periods optimizes for high query volume and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/insert/#mongodb-dbcommand-dbcmd.insert">
<code class="leafygreen-ui-1l06pbn">
insert
</code>
</a>
operations.
</p>
<p class="leafygreen-ui-1kp3ins">
To use custom bucketing parameters, set both parameters to the same
value, and do not set
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
bucketMaxSpanSeconds
</code>
sets the maximum time between timestamps
in the same bucket. Possible values are 1-31536000.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
bucketRoundingSeconds
</code>
sets the time interval that determines the
starting timestamp for a new bucket. When a document requires a new
bucket, MongoDB rounds down the document's timestamp value by this
interval to set the minimum time for the bucket.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For the weather station example, if you generate summary reports every
4 hours, you could adjust bucketing by setting the custom bucketing
parameters to 14400 seconds instead of using a
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
of
<code class="leafygreen-ui-1l06pbn">
"minutes"
</code>
:
</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 bucketMaxSpanSeconds: 14400,\n bucketRoundingSeconds: 14400\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">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">bucketMaxSpanSeconds</span>: <span class="lg-highlight-number">14400</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bucketRoundingSeconds</span>: <span class="lg-highlight-number">14400</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">
If a document with a time of
<code class="leafygreen-ui-1l06pbn">
2023-03-27T16:24:35Z
</code>
does not fit an
existing bucket, MongoDB creates a new bucket with a minimum time of
<code class="leafygreen-ui-1l06pbn">
2023-03-27T16:00:00Z
</code>
and a maximum time of
<code class="leafygreen-ui-1l06pbn">
2023-03-27T19:59:59Z
</code>
.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Change Time Series Granularity
<a class="headerlink leafygreen-ui-1kepx47" href="#change-time-series-granularity" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-time-series-granularity">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can increase
<code class="leafygreen-ui-1l06pbn">
timeseries.granularity
</code>
from a shorter unit of time
to a longer one using a
<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 timeseries: { granularity: \"seconds\" | \"minutes\" | \"hours\" }\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">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">timeseries</span>: <!-- -->{ <span class="lg-highlight-attr">granularity</span>: <span class="lg-highlight-string">"seconds"</span> <!-- -->| <span class="lg-highlight-string">"minutes"</span> <!-- -->| <span class="lg-highlight-string">"hours"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">} )</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If you are using the custom bucketing parameters
<code class="leafygreen-ui-1l06pbn">
bucketRoundingSeconds
</code>
and
<code class="leafygreen-ui-1l06pbn">
bucketMaxSpanSeconds
</code>
instead of
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
, include both custom parameters in the
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
command and set them to the same value:
</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 timeseries: {\n bucketRoundingSeconds: 86400,\n bucketMaxSpanSeconds: 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">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">timeseries</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bucketRoundingSeconds</span>: <span class="lg-highlight-number">86400</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bucketMaxSpanSeconds</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">
You cannot decrease the granularity interval or the custom bucketing
values.
</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">
To modify the granularity of a
<strong>
sharded
</strong>
time series collection,
you must be running MongoDB 6.0 or later.
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-migrate-data-into-timeseries-collection/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Migrate Data into a Time Series Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#migrate-data-into-a-time-series-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="migrate-data-into-a-time-series-collection">
</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="#optional.-create-a-metadata-field." target="_self">
<span>
Optional. Create a metadata field.
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-your-time-series-collection-and-insert-your-data." target="_self">
<span>
Create your time series collection and insert your data.
</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>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page describes how to migrate data into a time series collection
using an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
</a>
.
Alternatively, to learn how to migrate data into a time series
collection using MongoDB Relational Migrator, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/relational-migrator/mapping-rules/mapping-rule-options/time-series/" target="_self">
<span>
Configure a Time
Series Collection with Relational Migrator
</span>
</a>
.
</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">
Starting in MongoDB version 7.0, you can 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>
aggregation stage to migrate data from an existing collection into a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
time series collection
</a>
. If your
collection stores data that you want to compare across time intervals,
use a time series collection to improve performance and storage. For more
information on the benefits of time series collections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
Time Series Collections
<!-- -->
.
</a>
</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">
Consider a
<code class="leafygreen-ui-1l06pbn">
weatherdata
</code>
collection that contains time and metadata information:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weatherdata.insertOne(\n {\n _id: ObjectId(\"5553a998e4b02cf7151190b8\"),\n st: \"x+47600-047900\",\n ts: ISODate(\"1984-03-05T13:00:00Z\"),\n position: {\n type: \"Point\",\n coordinates: [ -47.9, 47.6 ]\n },\n elevation: 9999,\n callLetters: \"VCSZ\",\n qualityControlProcess: \"V020\",\n dataSource: \"4\",\n type: \"FM-13\",\n airTemperature: { value: -3.1, quality: \"1\" },\n dewPoint: { value: 999.9, quality : \"9\" },\n pressure: { value: 1015.3, quality: \"1\" },\n wind: {\n direction: { angle: 999, quality: \"9\" },\n type: \"9\",\n speed: { rate: 999.9, quality: \"9\" }\n },\n visibility: {\n distance: { value: 999999, quality : \"9\" },\n variability: { value: \"N\", quality: \"9\" }\n },\n skyCondition: {\n ceilingHeight: { value: 99999, quality: \"9\", determination: \"9\" },\n cavok: \"N\"\n },\n sections: [ \"AG1\" ],\n precipitationEstimatedObservation: {\n discrepancy: \"2\",\n estimatedWaterDepth: 999\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">weatherdata</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5553a998e4b02cf7151190b8"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">st</span>: <span class="lg-highlight-string">"x+47600-047900"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"1984-03-05T13:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">position</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">47.9</span>, <span class="lg-highlight-number">47.6</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">elevation</span>: <span class="lg-highlight-number">9999</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">callLetters</span>: <span class="lg-highlight-string">"VCSZ"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qualityControlProcess</span>: <span class="lg-highlight-string">"V020"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dataSource</span>: <span class="lg-highlight-string">"4"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"FM-13"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">airTemperature</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <!-- -->-<span class="lg-highlight-number">3.1</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dewPoint</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">999.9</span>, <!-- -->quality <!-- -->: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pressure</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">1015.3</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wind</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">direction</span>: <!-- -->{ <span class="lg-highlight-attr">angle</span>: <span class="lg-highlight-number">999</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"9"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">speed</span>: <!-- -->{ <span class="lg-highlight-attr">rate</span>: <span class="lg-highlight-number">999.9</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">visibility</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">distance</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">999999</span>, <!-- -->quality <!-- -->: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variability</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">"N"</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">skyCondition</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ceilingHeight</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">99999</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span>, <span class="lg-highlight-attr">determination</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cavok</span>: <span class="lg-highlight-string">"N"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sections</span>: <!-- -->[ <span class="lg-highlight-string">"AG1"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">precipitationEstimatedObservation</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">discrepancy</span>: <span class="lg-highlight-string">"2"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">estimatedWaterDepth</span>: <span class="lg-highlight-number">999</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>
<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":"If your collection does not include a specific field that contains\nall metadata, transform your data to define one.The following pipeline stages add a metaData field and use\n$project to include or exclude the remaining fields in\nthe document. In this example, the metaData field becomes the\nmetaField of the time series collection that you create.Choosing the right field as your time series metaField optimizes\nboth storage and query performance. For more information on\nmetaField selection and best practices, see\nmetaFields.","name":"Optional. Create a metadata field."},{"@type":"HowToStep","text":"The example below performs the following operations:Uses the $addFields aggregation stage to add a metaData field to\nyour weather_data collection.Uses the $out aggregation stage with the\ntimeseries option to create a weathernew time series\ncollection in the mydatabase database.Defines the metaField of your weathernew collection\nas the metaData field.Defines the timeField of your weathernew collection\nas the ts field.The timeField of a time series collection must be a date type.For the aggregation stage syntax, see\n$out. For a full explanation of the time series\noptions, see the Time Series Field Reference.","name":"Create your time series collection and insert your data."}],"name":"Steps","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>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Optional. Create a metadata field.
<a class="headerlink leafygreen-ui-1kepx47" href="#optional.-create-a-metadata-field." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="optional.-create-a-metadata-field.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your collection does not include a specific field that contains
all metadata, transform your data to define one.
</p>
<p class="leafygreen-ui-1kp3ins">
The following pipeline stages add a
<code class="leafygreen-ui-1l06pbn">
metaData
</code>
field and use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
</a>
to include or exclude the remaining fields in
the document. In this example, the
<code class="leafygreen-ui-1l06pbn">
metaData
</code>
field becomes the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
of the time series collection that you create.
</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">
Choosing the right field as your time series
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
optimizes
both storage and query performance. For more information on
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
selection and best practices, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-timeseries-collections-metafield">
metaFields
<!-- -->
.
</a>
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $addFields: {\n metaData: {\n st: \"$st\",\n position: \"$position\",\n elevation: \"$elevation\",\n callLetters: \"$callLetters\",\n qualityControlProcess: \"$qualityControlProcess\",\n type: \"$type\"\n }\n },\n},\n{ $project: {\n _id: 1,\n ts: 1,\n metaData: 1,\n dataSource: 1,\n airTemperature: 1,\n dewPoint: 1,\n pressure: 1,\n wind: 1,\n visibility: 1,\n skyCondition: 1,\n sections: 1,\n precipitationEstimatedObservation: 1\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">{ <span class="lg-highlight-attr">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaData</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">st</span>: <span class="lg-highlight-string">"$st"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">position</span>: <span class="lg-highlight-string">"$position"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">elevation</span>: <span class="lg-highlight-string">"$elevation"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">callLetters</span>: <span class="lg-highlight-string">"$callLetters"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qualityControlProcess</span>: <span class="lg-highlight-string">"$qualityControlProcess"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"$type"</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-attr">$project</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">ts</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaData</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dataSource</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">airTemperature</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dewPoint</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pressure</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wind</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">visibility</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">skyCondition</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sections</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">precipitationEstimatedObservation</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>
</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>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create your time series collection and insert your data.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-your-time-series-collection-and-insert-your-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="create-your-time-series-collection-and-insert-your-data.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The example below performs the following operations:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Uses 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>
aggregation stage to add a
<code class="leafygreen-ui-1l06pbn">
metaData
</code>
field to
your
<code class="leafygreen-ui-1l06pbn">
weather_data
</code>
collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Uses 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>
aggregation stage with the
<code class="leafygreen-ui-1l06pbn">
timeseries
</code>
option to create a
<code class="leafygreen-ui-1l06pbn">
weathernew
</code>
time series
collection in the
<code class="leafygreen-ui-1l06pbn">
mydatabase
</code>
database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Defines the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
of your
<code class="leafygreen-ui-1l06pbn">
weathernew
</code>
collection
as the
<code class="leafygreen-ui-1l06pbn">
metaData
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Defines the
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
of your
<code class="leafygreen-ui-1l06pbn">
weathernew
</code>
collection
as the
<code class="leafygreen-ui-1l06pbn">
ts
</code>
field.
</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">
The
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
of a time series collection must be a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-types/#std-label-document-bson-type-date">
date
</a>
type.
</p>
</div>
</div>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weather_data.aggregate( [\n {\n $addFields: {\n metaData: {\n st: \"$st\",\n position: \"$position\",\n elevation: \"$elevation\",\n callLetters: \"$callLetters\",\n qualityControlProcess: \"$qualityControlProcess\",\n type: \"$type\"\n }\n },\n }, {\n $project: {\n _id: 1,\n ts: 1,\n metaData: 1,\n dataSource: 1,\n airTemperature: 1,\n dewPoint: 1,\n pressure: 1,\n wind: 1,\n visibility: 1,\n skyCondition: 1,\n sections: 1,\n precipitationEstimatedObservation: 1\n }\n }, {\n $out: {\n db: \"mydatabase\",\n coll: \"weathernew\",\n timeseries: {\n timeField: \"ts\",\n metaField: \"metaData\"\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">weather_data</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">$addFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaData</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">st</span>: <span class="lg-highlight-string">"$st"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">position</span>: <span class="lg-highlight-string">"$position"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">elevation</span>: <span class="lg-highlight-string">"$elevation"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">callLetters</span>: <span class="lg-highlight-string">"$callLetters"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qualityControlProcess</span>: <span class="lg-highlight-string">"$qualityControlProcess"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"$type"</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-attr">$project</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">ts</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaData</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dataSource</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">airTemperature</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dewPoint</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pressure</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wind</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">visibility</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">skyCondition</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sections</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">precipitationEstimatedObservation</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">$out</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"mydatabase"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">"weathernew"</span>,</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">"ts"</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"> }</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">
For the aggregation stage syntax, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
</a>
. For a full explanation of the time series
options, see the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-procedures/#std-label-time-series-fields">
Time Series Field Reference
<!-- -->
.
</a>
</p>
</section>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
After you run this aggregation pipeline, you can use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOne/#mongodb-method-db.collection.findOne">
<code class="leafygreen-ui-1l06pbn">
findOne()
</code>
</a>
to view a document in your
<code class="leafygreen-ui-1l06pbn">
weathernew
</code>
time series collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weathernew.findOne()","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">weathernew</span>.<span class="lg-highlight-title lg-highlight-function">findOne</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 document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":" {\n _id: ObjectId(\"5553a998e4b02cf7151190b8\"),\n ts: ISODate(\"1984-03-05T13:00:00Z\"),\n metaData: {\n st: \"x+47600-047900\",\n position: {\n type: \"Point\",\n coordinates: [ -47.9, 47.6 ]\n },\n elevation: 9999,\n callLetters: \"VCSZ\",\n qualityControlProcess: \"V020\",\n type: \"FM-13\"\n },\n dataSource: \"4\",\n airTemperature: { value: -3.1, quality: \"1\" },\n dewPoint: { value: 999.9, quality: \"9\" },\n pressure: { value: 1015.3, quality: \"1\" },\n wind: {\n direction: { angle: 999, quality: \"9\" },\n type: \"9\",\n speed: { rate: 999.9, quality: \"9\" }\n },\n visibility: {\n distance: { value: 999999, quality: \"9\" },\n variability: { value: \"N\", quality: \"9\" }\n },\n skyCondition: {\n ceilingHeight: { value: 99999, quality: \"9\", determination: \"9\" },\n cavok: \"N\"\n },\n sections: [ \"AG1\" ],\n precipitationEstimatedObservation: { discrepancy: \"2\", estimatedWaterDepth: 999 }\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">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5553a998e4b02cf7151190b8"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ts</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"1984-03-05T13:00:00Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaData</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">st</span>: <span class="lg-highlight-string">"x+47600-047900"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">position</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"Point"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[ <!-- -->-<span class="lg-highlight-number">47.9</span>, <span class="lg-highlight-number">47.6</span> ]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">elevation</span>: <span class="lg-highlight-number">9999</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">callLetters</span>: <span class="lg-highlight-string">"VCSZ"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qualityControlProcess</span>: <span class="lg-highlight-string">"V020"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"FM-13"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dataSource</span>: <span class="lg-highlight-string">"4"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">airTemperature</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <!-- -->-<span class="lg-highlight-number">3.1</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">dewPoint</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">999.9</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pressure</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">1015.3</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"1"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">wind</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">direction</span>: <!-- -->{ <span class="lg-highlight-attr">angle</span>: <span class="lg-highlight-number">999</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"9"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">speed</span>: <!-- -->{ <span class="lg-highlight-attr">rate</span>: <span class="lg-highlight-number">999.9</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">visibility</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">distance</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">999999</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variability</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">"N"</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">skyCondition</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">ceilingHeight</span>: <!-- -->{ <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">99999</span>, <span class="lg-highlight-attr">quality</span>: <span class="lg-highlight-string">"9"</span>, <span class="lg-highlight-attr">determination</span>: <span class="lg-highlight-string">"9"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cavok</span>: <span class="lg-highlight-string">"N"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sections</span>: <!-- -->[ <span class="lg-highlight-string">"AG1"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">precipitationEstimatedObservation</span>: <!-- -->{ <span class="lg-highlight-attr">discrepancy</span>: <span class="lg-highlight-string">"2"</span>, <span class="lg-highlight-attr">estimatedWaterDepth</span>: <span class="lg-highlight-number">999</span> }</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">
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">
If your original collection had secondary indexes, manually recreate
them now.
</p>
<p class="leafygreen-ui-1kp3ins">
If your time series collection includes
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
values before
<code class="leafygreen-ui-1l06pbn">
1970-01-01T00:00:00.000Z
</code>
or after
<code class="leafygreen-ui-1l06pbn">
2038-01-19T03:14:07.000Z
</code>
,
MongoDB logs a warning and disables some query optimizations that make
use of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-internal-index">
internal clustered index
</a>
. To regain query performance and
resolve the log warning,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index">
create a secondary index
</a>
on the
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
.
</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/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index">
Add Secondary Indexes to Time Series Collections
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/timeseries/timeseries-best-practices/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Best Practices for Time Series Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#best-practices-for-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="best-practices-for-time-series-collections">
</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="#compression-best-practices" target="_self">
<span>
Compression Best Practices
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#omit-fields-containing-empty-objects-and-arrays-from-documents" target="_self">
<span>
Omit Fields Containing Empty Objects and Arrays from Documents
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#round-numeric-data-to-few-decimal-places" target="_self">
<span>
Round Numeric Data to Few Decimal Places
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#inserts-best-practices" target="_self">
<span>
Inserts Best Practices
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#batch-document-writes" target="_self">
<span>
Batch Document Writes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-consistent-field-order-in-documents" target="_self">
<span>
Use Consistent Field Order in Documents
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#increase-the-number-of-clients" target="_self">
<span>
Increase the Number of Clients
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#sharding-best-practices" target="_self">
<span>
Sharding Best Practices
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use-the-metafield-as-your-shard-key" target="_self">
<span>
Use the
<code class="css-1kekw28 e1wawog0">
metaField
</code>
as your Shard Key
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#query-best-practices" target="_self">
<span>
Query Best Practices
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#set-a-strategic-metafield-when-creating-the-collection" target="_self">
<span>
Set a Strategic
<code class="css-1kekw28 e1wawog0">
metaField
</code>
When Creating the Collection
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#set-appropriate-bucket-granularity" target="_self">
<span>
Set Appropriate Bucket Granularity
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-secondary-indexes" target="_self">
<span>
Create Secondary Indexes
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#additional-index-best-practices" target="_self">
<span>
Additional Index Best Practices
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-the-metafield-on-sub-fields" target="_self">
<span>
Query the
<code class="css-1kekw28 e1wawog0">
metaField
</code>
on Sub-Fields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#use--group-instead-of-distinct--" target="_self">
<span>
Use $group Instead of Distinct()
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
This page describes best practices to improve performance and data usage
for time series collections.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-tsc-best-practice-optimize-compression">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Compression Best Practices
<a class="headerlink leafygreen-ui-1kepx47" href="#compression-best-practices" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-best-practices">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To optimize data compression for time series collections, perform the
following actions:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Omit Fields Containing Empty Objects and Arrays from Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#omit-fields-containing-empty-objects-and-arrays-from-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="omit-fields-containing-empty-objects-and-arrays-from-documents">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If your data contains empty objects, arrays, or strings, omit the empty
fields from your documents to optimize compression.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, consider the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n timestamp: ISODate(\"2020-01-23T00:00:00.441Z\"),\n coordinates: [1.0, 2.0]\n},\n{\n timestamp: ISODate(\"2020-01-23T00:00:10.441Z\"),\n coordinates: []\n},\n{\n timestamp: ISODate(\"2020-01-23T00:00:20.441Z\"),\n coordinates: [3.0, 5.0]\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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:00.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[<span class="lg-highlight-number">1.0</span>, <span class="lg-highlight-number">2.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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:10.441Z"</span>)<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:20.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[<span class="lg-highlight-number">3.0</span>, <span class="lg-highlight-number">5.0</span>]</td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
coordinates
</code>
fields with populated values and
<code class="leafygreen-ui-1l06pbn">
coordinates
</code>
fields
with an empty array result in a schema change for the compressor. The
schema change causes the second and third documents in the sequence to
remain uncompressed.
</p>
<p class="leafygreen-ui-1kp3ins">
Optimize compression by omitting the fields with empty values, as shown
in the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n timestamp: ISODate(\"2020-01-23T00:00:00.441Z\"),\n coordinates: [1.0, 2.0]\n},\n{\n timestamp: ISODate(\"2020-01-23T00:00:10.441Z\")\n},\n{\n timestamp: ISODate(\"2020-01-23T00:00:20.441Z\"),\n coordinates: [3.0, 5.0]\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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:00.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[<span class="lg-highlight-number">1.0</span>, <span class="lg-highlight-number">2.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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:10.441Z"</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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:20.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coordinates</span>: <!-- -->[<span class="lg-highlight-number">3.0</span>, <span class="lg-highlight-number">5.0</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">
Round Numeric Data to Few Decimal Places
<a class="headerlink leafygreen-ui-1kepx47" href="#round-numeric-data-to-few-decimal-places" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="round-numeric-data-to-few-decimal-places">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Round numeric data to the precision that your application requires.
Rounding numeric data to fewer decimal places improves the compression
ratio.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-tsc-best-practice-optimize-inserts">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Inserts Best Practices
<a class="headerlink leafygreen-ui-1kepx47" href="#inserts-best-practices" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="inserts-best-practices">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To optimize insert performance for time series collections, perform the
following actions:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Batch Document Writes
<a class="headerlink leafygreen-ui-1kepx47" href="#batch-document-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="batch-document-writes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When inserting multiple documents:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To avoid network roundtrips, use a single
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertMany/#mongodb-method-db.collection.insertMany">
<code class="leafygreen-ui-1l06pbn">
insertMany()
</code>
</a>
statement as opposed to
multiple
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertOne/#mongodb-method-db.collection.insertOne">
<code class="leafygreen-ui-1l06pbn">
insertOne()
</code>
</a>
statements.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If possible, insert data that contains identical
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
values in
the same batches.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Set the
<code class="leafygreen-ui-1l06pbn">
ordered
</code>
parameter to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For example, if you have two sensors that correspond to two
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
values,
<code class="leafygreen-ui-1l06pbn">
sensor A
</code>
and
<code class="leafygreen-ui-1l06pbn">
sensor B
</code>
, a batch that contains multiple
measurements from a single sensor incurs the cost of one insert, rather
than one insert per measurement.
</p>
<p class="leafygreen-ui-1kp3ins">
The following operation inserts six documents, but only incurs the cost
of two inserts (one per
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
value), because the documents are
ordered by sensor. The
<code class="leafygreen-ui-1l06pbn">
ordered
</code>
parameter is set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
to
improve performance:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.insertMany(\n [\n {\n metaField: {\n sensor: \"sensorA\"\n },\n timestamp: ISODate(\"2021-05-18T00:00:00.000Z\"),\n temperature: 10\n },\n {\n metaField: {\n sensor: \"sensorA\"\n },\n timestamp: ISODate(\"2021-05-19T00:00:00.000Z\"),\n temperature: 12\n },\n {\n metaField: {\n sensor: \"sensorA\"\n },\n timestamp: ISODate(\"2021-05-20T00:00:00.000Z\"),\n temperature: 13\n },\n {\n metaField: {\n sensor: \"sensorB\"\n },\n timestamp: ISODate(\"2021-05-18T00:00:00.000Z\"),\n temperature: 20\n },\n {\n metaField: {\n sensor: \"sensorB\"\n },\n timestamp: ISODate(\"2021-05-19T00:00:00.000Z\"),\n temperature: 25\n },\n {\n metadField: {\n sensor: \"sensorB\"\n },\n timestamp: ISODate(\"2021-05-20T00:00:00.000Z\"),\n temperature: 26\n }\n ],\n { \"ordered\": 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">db.<span class="lg-highlight-property">temperatures</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-attr">metaField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorA"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</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">metaField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorA"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-19T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</span>: <span class="lg-highlight-number">12</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">metaField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorA"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-20T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</span>: <span class="lg-highlight-number">13</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">metaField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorB"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</span>: <span class="lg-highlight-number">20</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">metaField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorB"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-19T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</span>: <span class="lg-highlight-number">25</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">metadField</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sensor</span>: <span class="lg-highlight-string">"sensorB"</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-20T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temperature</span>: <span class="lg-highlight-number">26</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">"ordered"</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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use Consistent Field Order in Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#use-consistent-field-order-in-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="use-consistent-field-order-in-documents">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using a consistent field order in your documents improves insert
performance.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, inserting the following documents, all of which have the
same field order, results in optimal insert performance.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: ObjectId(\"6250a0ef02a1877734a9df57\"),\n timestamp: ISODate(\"2020-01-23T00:00:00.441Z\"),\n name: \"sensor1\",\n range: 1\n},\n{\n _id: ObjectId(\"6560a0ef02a1877734a9df66\"),\n timestamp: ISODate(\"2020-01-23T01:00:00.441Z\"),\n name: \"sensor1\",\n range: 5\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6250a0ef02a1877734a9df57"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:00.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"sensor1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</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">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6560a0ef02a1877734a9df66"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T01:00:00.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"sensor1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <span class="lg-highlight-number">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">
In contrast, the following documents
<em>
do not
</em>
achieve optimal insert
performance, because their field orders differ:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n range: 1,\n _id: ObjectId(\"6250a0ef02a1877734a9df57\"),\n name: \"sensor1\",\n timestamp: ISODate(\"2020-01-23T00:00:00.441Z\")\n},\n{\n _id: ObjectId(\"6560a0ef02a1877734a9df66\"),\n name: \"sensor1\",\n timestamp: ISODate(\"2020-01-23T01:00:00.441Z\"),\n range: 5\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">range</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6250a0ef02a1877734a9df57"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"sensor1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T00:00:00.441Z"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6560a0ef02a1877734a9df66"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"sensor1"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-23T01:00:00.441Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <span class="lg-highlight-number">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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Increase the Number of Clients
<a class="headerlink leafygreen-ui-1kepx47" href="#increase-the-number-of-clients" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="increase-the-number-of-clients">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Increasing the number of clients that write data to your collections can
improve performance.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-tsc-best-practice-optimize-sharding">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Sharding Best Practices
<a class="headerlink leafygreen-ui-1kepx47" href="#sharding-best-practices" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="sharding-best-practices">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To optimize sharding on your time series collection, perform the
following action:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
as your Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#use-the-metafield-as-your-shard-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="use-the-metafield-as-your-shard-key">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Using the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
to shard your collection provides sufficienct
cardinality as a shard key for time series 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">
Starting in MongoDB 8.0, the use of the
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
as a shard key
in time series collections is deprecated.
</p>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-tsc-best-practice-optimize-query-performance">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Query Best Practices
<a class="headerlink leafygreen-ui-1kepx47" href="#query-best-practices" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-best-practices">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
To optimize queries on your time series collection, perform the
following actions:
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Set a Strategic
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
When Creating the Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#set-a-strategic-metafield-when-creating-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="set-a-strategic-metafield-when-creating-the-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Your choice of
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
has the
biggest impact on optimizing queries in your application.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select fields that rarely or never change as part of your metaField.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If possible, select identifiers or other stable values that are common in filter
expressions as part of your metaField.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Avoid selecting fields that are not used for filtering as part of your
metaField. Instead, use those fields as measurements.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-considerations/#std-label-timeseries-metafield-considerations">
metaField Considerations
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Set Appropriate Bucket Granularity
<a class="headerlink leafygreen-ui-1kepx47" href="#set-appropriate-bucket-granularity" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-appropriate-bucket-granularity">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you create a time series collection, MongoDB groups incoming time
series data into buckets. By accurately setting granularity, you control
how frequently data is bucketed based on the ingestion rate of your data.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.3, you can use the custom bucketing parameters
<code class="leafygreen-ui-1l06pbn">
bucketMaxSpanSeconds
</code>
and
<code class="leafygreen-ui-1l06pbn">
bucketRoundingSeconds
</code>
to specify bucket
boundaries and more precisely control how time series data is bucketed.
</p>
<p class="leafygreen-ui-1kp3ins">
You can improve performance by setting the
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
or custom
bucketing parameters to the best match for the time span between
incoming measurements from the same data source. For example, if you are
recording weather data from thousands of sensors but only record data
from each sensor once per 5 minutes, you can either set
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
to
<code class="leafygreen-ui-1l06pbn">
"minutes"
</code>
or set the custom bucketing parameters to
<code class="leafygreen-ui-1l06pbn">
300
</code>
(seconds).
</p>
<p class="leafygreen-ui-1kp3ins">
In this case, setting the
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
to
<code class="leafygreen-ui-1l06pbn">
hours
</code>
groups up to a
month's worth of data ingest events into a single bucket, resulting in
longer traversal times and slower queries. Setting it to
<code class="leafygreen-ui-1l06pbn">
seconds
</code>
leads to multiple buckets per polling interval, many of which
might contain only a single document.
</p>
<p class="leafygreen-ui-1kp3ins">
The following table shows the maximum time interval included in one
bucket of data when using a given
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
value:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:20%"/>
<col style="width:30%"/>
</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>
<code class="leafygreen-ui-1l06pbn">
granularity
</code>
bucket limit
</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>
1 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>
<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/timeseries/timeseries-automatic-removal/#std-label-timeseries-collection-delete-operations-timing">
Timing of Automatic Removal
</a>
</p>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create Secondary Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#create-secondary-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-secondary-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To improve query performance,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-secondary-index/#std-label-timeseries-add-secondary-index">
create one or more secondary indexes
</a>
on your
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
and
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
to support common query patterns. In versions 6.3 and
higher, MongoDB creates a secondary index on the
<code class="leafygreen-ui-1l06pbn">
timeField
</code>
and
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
automatically.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Additional Index Best Practices
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-index-best-practices" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-index-best-practices">
</div>
</a>
</h3>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the metaField index for filtering and equality.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Use the timeField and other indexed fields for range queries.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
General indexing strategies also apply to time series collections. For
more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/applications/indexes/#std-label-indexing-strategies">
Indexing Strategies
<!-- -->
.
</a>
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
on Sub-Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#query-the-metafield-on-sub-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="query-the-metafield-on-sub-fields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB reorders the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
of time-series collections, which may
cause servers to store data in a different field order than
applications. If a
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
is an object, queries on the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
may produce inconsistent results because
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
order may vary
between servers and applications. To optimize queries on a time-series
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
, query the
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
on scalar sub-fields rather than
the entire
<code class="leafygreen-ui-1l06pbn">
metaField
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The following example creates a time series collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weather.insertMany( [\n {\n metaField: { sensorId: 5578, type: \"temperature\" },\n timestamp: ISODate( \"2021-05-18T00:00:00.000Z\" ),\n temp: 12\n },\n {\n metaField: { sensorId: 5578, type: \"temperature\" },\n timestamp: ISODate( \"2021-05-18T04:00:00.000Z\" ),\n temp: 11\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">weather</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">metaField</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span> )<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">12</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">metaField</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-05-18T04:00:00.000Z"</span> )<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">11</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 on the
<code class="leafygreen-ui-1l06pbn">
sensorId
</code>
and
<code class="leafygreen-ui-1l06pbn">
type
</code>
scalar sub-fields
returns the first document that matches the query criteria:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weather.findOne( {\n \"metaField.sensorId\": 5578,\n \"metaField.type\": \"temperature\"\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">weather</span>.<span class="lg-highlight-title lg-highlight-function">findOne</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metaField.sensorId"</span>: <span class="lg-highlight-number">5578</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"metaField.type"</span>: <span class="lg-highlight-string">"temperature"</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 _id: ObjectId(\"6572371964eb5ad43054d572\"),\n metaField: { sensorId: 5578, type: 'temperature' },\n timestamp: ISODate( \"2021-05-18T00:00:00.000Z\" ),\n temp: 12\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"6572371964eb5ad43054d572"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metaField</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'temperature'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>( <span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span> )<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">12</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">
Use $group Instead of Distinct()
<a class="headerlink leafygreen-ui-1kepx47" href="#use--group-instead-of-distinct--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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--group-instead-of-distinct--">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Due to the unique data structure of time series collections, MongoDB can't
efficiently index them for distinct values. Avoid using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
</a>
command or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.distinct/#mongodb-method-db.collection.distinct">
<code class="leafygreen-ui-1l06pbn">
db.collection.distinct()
</code>
</a>
helper
method on time series collections. Instead, use a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
aggregation to group documents by distinct values.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, to query for distinct
<code class="leafygreen-ui-1l06pbn">
meta.type
</code>
values on documents
where
<code class="leafygreen-ui-1l06pbn">
meta.project = 10
</code>
, instead of:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.foo.distinct(\"meta.type\", {\"meta.project\": 10})","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">foo</span>.<span class="lg-highlight-title lg-highlight-function">distinct</span>(<span class="lg-highlight-string">"meta.type"</span>, <!-- -->{<span class="lg-highlight-string">"meta.project"</span>: <span class="lg-highlight-number">10</span>})</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Use:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.foo.createIndex({\"meta.project\":1, \"meta.type\":1})\ndb.foo.aggregate([{$match: {\"meta.project\": 10}},\n {$group: {_id: \"$meta.type\"}}])","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">foo</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>(<!-- -->{<span class="lg-highlight-string">"meta.project"</span>:<span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"meta.type"</span>:<span class="lg-highlight-number">1</span>})</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">foo</span>.<span class="lg-highlight-title lg-highlight-function">aggregate</span>(<!-- -->[<!-- -->{<span class="lg-highlight-attr">$match</span>: <!-- -->{<span class="lg-highlight-string">"meta.project"</span>: <span class="lg-highlight-number">10</span>}}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{<span class="lg-highlight-attr">$group</span>: <!-- -->{<span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$meta.type"</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 works as follows:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Creating a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-compound/#std-label-index-type-compound">
compound index
</a>
on
<code class="leafygreen-ui-1l06pbn">
meta.project
</code>
and
<code class="leafygreen-ui-1l06pbn">
meta.type
</code>
and supports the aggregation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<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 filters for documents where
<code class="leafygreen-ui-1l06pbn">
meta.project = 10
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
stage uses
<code class="leafygreen-ui-1l06pbn">
meta.type
</code>
as the group key to output
one document per unique value.
</p>
</li>
</ol>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/updateZoneKeyRange/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
updateZoneKeyRange
<a class="headerlink leafygreen-ui-1kepx47" href="#updatezonekeyrange" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="updatezonekeyrange">
</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="#security" target="_self">
<span>
Security
</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">
updateZoneKeyRange
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" 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.updateZoneKeyRange">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
administrative command can either
create or remove the association between a range of shard key values and a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-zone">
zone
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
database command and its helpers
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.addTagRange/#mongodb-method-sh.addTagRange">
<code class="leafygreen-ui-1l06pbn">
sh.addTagRange()
</code>
</a>
on
an unsharded collection or a non-existing 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/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</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">
To run
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.runCommand/#mongodb-method-db.runCommand">
<code class="leafygreen-ui-1l06pbn">
db.runCommand( { <command> } )
</code>
</a>
method.
</p>
<p class="leafygreen-ui-1kp3ins">
You must run
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/addShardToZone/#mongodb-dbcommand-dbcmd.addShardToZone">
<code class="leafygreen-ui-1l06pbn">
addShardToZone
</code>
</a>
on the admin 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 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">
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 updateZoneKeyRange: <string>,\n min: <document>,\n max: <document>,\n zone: <string> | <null>\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">updateZoneKeyRange</span>: <<!-- -->string<!-- -->><!-- -->,</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">zone</span>: <<!-- -->string<!-- -->> <!-- -->| <<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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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>
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">
updateZoneKeyRange
</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 namespace of the collection to associate with the range.
</p>
<p class="leafygreen-ui-1kp3ins">
The collection must be sharded for the command to succeed.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<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>
<p class="leafygreen-ui-1kp3ins">
The inclusive lower bound of the range of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify each field of the shard key in the form of
<code class="leafygreen-ui-1l06pbn">
<fieldname> : <value>
</code>
.
The value must be of the same BSON type or types as the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
To use hashed sharding, the field value of
<code class="leafygreen-ui-1l06pbn">
min
</code>
needs
to be of type
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
<code class="leafygreen-ui-1l06pbn">
NumberLong
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<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>
<p class="leafygreen-ui-1kp3ins">
The exclusive upper bound of the range of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
values.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify each field of the shard key in the form of
<code class="leafygreen-ui-1l06pbn">
<fieldname> : <value>
</code>
.
The value must be of the same BSON type or types as the shard key.
</p>
<p class="leafygreen-ui-1kp3ins">
To use hashed sharding, the field value of
<code class="leafygreen-ui-1l06pbn">
max
</code>
needs
to be of type
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/mongodb-extended-json-v1/#mongodb-bsontype-data_numberlong">
<code class="leafygreen-ui-1l06pbn">
NumberLong
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
zone
</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 name of the zone to associate with the range bounded by the
<code class="leafygreen-ui-1l06pbn">
min
</code>
and
<code class="leafygreen-ui-1l06pbn">
max
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If the value does not match an existing zone, the command fails.
</p>
<p class="leafygreen-ui-1kp3ins">
Specify
<code class="leafygreen-ui-1l06pbn">
null
</code>
to remove the association between the range with lower
bounds of
<code class="leafygreen-ui-1l06pbn">
min
</code>
and upper bound of
<code class="leafygreen-ui-1l06pbn">
max
</code>
and the
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
collection. The values of
<code class="leafygreen-ui-1l06pbn">
min
</code>
and
<code class="leafygreen-ui-1l06pbn">
max
</code>
must match exactly the target
range.
</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">
If no zone range matches the minimum and maximum bounds passed to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
, nothing is removed.
</p>
<p class="leafygreen-ui-1kp3ins">
Only issue
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
when connected 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.
</p>
<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 two helper 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/sh.updateZoneKeyRange/#mongodb-method-sh.updateZoneKeyRange">
<code class="leafygreen-ui-1l06pbn">
sh.updateZoneKeyRange()
</code>
</a>
for adding a range of shard key values to a
zone.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.removeRangeFromZone/#mongodb-method-sh.removeRangeFromZone">
<code class="leafygreen-ui-1l06pbn">
sh.removeRangeFromZone()
</code>
</a>
for removing a range of shard key values
from a zone.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You cannot create a range of shard key values whose lower and upper boundaries
overlap with an existing range for the sharded collection. For example, given
an existing range of
<code class="leafygreen-ui-1l06pbn">
1
</code>
to
<code class="leafygreen-ui-1l06pbn">
10
</code>
, you cannot create a new range of
<code class="leafygreen-ui-1l06pbn">
5
</code>
to
<code class="leafygreen-ui-1l06pbn">
20
</code>
, as the new range would overlap with the existing range.
</p>
<p class="leafygreen-ui-1kp3ins">
A zone can have multiple ranges of data associated with it, but a range
can at most be associated with a single zone.
</p>
<p class="leafygreen-ui-1kp3ins">
When removing the association between a range and a zone,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
does not remove the zone. Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeShardFromZone/#mongodb-dbcommand-dbcmd.removeShardFromZone">
<code class="leafygreen-ui-1l06pbn">
removeShardFromZone
</code>
</a>
command to remove the association between a
zone and a shard.
</p>
<p class="leafygreen-ui-1kp3ins">
See the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zone
</a>
manual page for more information on zones
in sharded clusters.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updateZoneKeyRange-cmd-init-chunk-distribution">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initial Chunk Distribution for Empty or Non-Existing Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-for-empty-or-non-existing-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="initial-chunk-distribution-for-empty-or-non-existing-collections">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If you are considering performing
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/zone-sharding/#std-label-zone-sharding">
zone sharding
</a>
on an empty or non-existent collection, use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
to create the zones and zone ranges
<em>
before
</em>
sharding the collection (
<em>
since 4.0.2
</em>
). Starting in version
4.0.3, creating zones and zone ranges on empty or non-existing
collections allows MongoDB to optimize the initial chunk creation and
distribution process when sharding the collection. This optimized
process supports faster setup of zoned sharding with less balancer
overhead than creating zones after sharding. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
balancer
</a>
performs all chunk management after the optimized
initial chunk creation and distribution.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example of defining zones and zone ranges for initial chunk
distribution, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-example">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</a>
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Initial Chunk Distribution with Compound Hashed Shard Keys
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-chunk-distribution-with-compound-hashed-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="initial-chunk-distribution-with-compound-hashed-shard-keys">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB supports sharding collections on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/indexes/index-types/index-hashed/create/#std-label-index-type-compound-hashed">
compound hashed indexes
</a>
. MongoDB can
perform optimized initial chunk creation and distribution when sharding
the empty or non-existing collection on a compound hashed shard key.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-12">
<div aria-label="Tabs to describe usage of hash-not-prefix/hash-prefix" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_tgil984rf" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_p1519p8w2" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field Is Prefix
</div>
</button>
<button aria-controls="_cd5o2ca40" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_9t69cbiro" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Hashed Field is Not Prefix
</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="_usvyc5np9" class="" id="_k7etz0unp" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is the prefix of the shard key (i.e. the first
field in the shard key), all of the following must be true for
MongoDB to perform initial chunk creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has a single zone range with
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
all lower-bound fields and
<code class="leafygreen-ui-1l06pbn">
MaxKey
</code>
for all upper-bound
fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
<div>
<div aria-labelledby="_bmqmzdmav" class="leafygreen-ui-38lglc" id="_bptjb1f8n" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If the hashed field is
<em>
not
</em>
the prefix of the shard key (i.e.
the shard key has one or more non-hashed leading fields), all of
the following must be true for MongoDB to perform initial chunk
creation and distribution:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The collection has one zone range for each combination of distinct
prefix field values (i.e. all fields preceding the hashed field).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the lower-bound of each zone range, specify
<code class="leafygreen-ui-1l06pbn">
MinKey
</code>
for
the hashed field and all subsequent fields.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For each zone range, at least one upper-bound prefix field
<em>
must
</em>
differ from its lower-bound counterpart.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#mongodb-method-sh.shardCollection">
<code class="leafygreen-ui-1l06pbn">
sh.shardCollection()
</code>
</a>
specifies the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.shardCollection/#std-label-method-shard-collection-presplitHashedZones">
presplitHashedZones: true
</a>
option.
</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For a more complete example of defining zones and zone ranges for
initial chunk distribution on a compound hashed shard key, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/sh.updateZoneKeyRange/#std-label-pre-define-zone-range-hashed-example">
Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Balancer
<a class="headerlink leafygreen-ui-1kepx47" href="#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="balancer">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
After successfully running
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
, there may be chunk
migrations during the next balancer round.
</p>
<p class="leafygreen-ui-1kp3ins">
After adding a range to a zone, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing-internals">
balancer
</a>
must first run in order to migrate any
chunks whose ranges are covered by the zone to shards inside
of that zone. Until balancing completes, some chunks may reside on the
wrong shard given the configured zones for the sharded cluster.
</p>
<p class="leafygreen-ui-1kp3ins">
Removing the association between a range and a zone removes the constraints
keeping chunks covered by the range on the shards inside that zone. During the
next balancer round, the balancer may migrate chunks that were previously
covered by the zone.
</p>
<p class="leafygreen-ui-1kp3ins">
See the documentation for the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-balancer-administration/#std-label-sharding-balancing">
sharded cluster balancer
</a>
for more information on how migrations work in a sharded
cluster.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Bounds
<a class="headerlink leafygreen-ui-1kepx47" href="#bounds" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="bounds">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Zone ranges are always inclusive of the lower boundary and exclusive
of the upper boundary.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Dropped Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#dropped-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">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Dropping a collection deletes its associated zone/tag ranges.
</p>
<p class="leafygreen-ui-1kp3ins">
In earlier versions, MongoDB does not remove the tag associations for a
dropped collection, and if you later create a new collection with the
same name, the old tag associations will apply to the new collection.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Security
<a class="headerlink leafygreen-ui-1kepx47" href="#security" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="security">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For sharded clusters running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authentication/#std-label-authentication">
authentication
</a>
, you
must authenticate as either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a user whose privileges include the specified actions on various
collections in the
<code class="leafygreen-ui-1l06pbn">
config
</code>
database:
</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/privilege-actions/#mongodb-authaction-find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
config.shards
</code>
collection
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-update">
<code class="leafygreen-ui-1l06pbn">
update
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-remove">
<code class="leafygreen-ui-1l06pbn">
remove
</code>
</a>
on the
<code class="leafygreen-ui-1l06pbn">
config.tags
</code>
collection;
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
or, alternatively,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a user whose privileges include
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-enableSharding">
<code class="leafygreen-ui-1l06pbn">
enableSharding
</code>
</a>
on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/resource-document/#std-label-resource-specific-collection">
cluster
</a>
resource.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterAdmin">
<code class="leafygreen-ui-1l06pbn">
clusterAdmin
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterManager">
<code class="leafygreen-ui-1l06pbn">
clusterManager
</code>
</a>
built-in roles have
the appropriate permissions for issuing
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
. See
the documentation page for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/authorization/#std-label-authorization">
Role-Based Access Control
</a>
for more information.
</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">
Given a sharded collection
<code class="leafygreen-ui-1l06pbn">
exampledb.collection
</code>
with a shard key of
<code class="leafygreen-ui-1l06pbn">
{ a
: 1 }
</code>
, the following operation creates a range with a lower bound of
<code class="leafygreen-ui-1l06pbn">
1
</code>
and an upper bound of
<code class="leafygreen-ui-1l06pbn">
10
</code>
on the
<code class="leafygreen-ui-1l06pbn">
alpha
</code>
zone:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.runCommand(\n {\n updateZoneKeyRange : \"exampledb.collection\",\n min : { a : 1 },\n max : { a : 10 },\n zone : \"alpha\"\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">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">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->updateZoneKeyRange <!-- -->: <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->min <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->max <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->zone <!-- -->: <span class="lg-highlight-string">"alpha"</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 operation removes the previously created range by passing
<code class="leafygreen-ui-1l06pbn">
null
</code>
to the
<code class="leafygreen-ui-1l06pbn">
zone
</code>
field.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.runCommand(\n {\n updateZoneKeyRange : \"exampledb.collection\",\n min : { a : 1 },\n max : { a : 10 },\n zone : null\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">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">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->updateZoneKeyRange <!-- -->: <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->min <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->max <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->zone <!-- -->: <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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
min
</code>
and
<code class="leafygreen-ui-1l06pbn">
max
</code>
must match exactly the bounds of the target range.
The following operation attempts to remove the previously created range, but
specifies
<code class="leafygreen-ui-1l06pbn">
{ a : 0 }
</code>
as the
<code class="leafygreen-ui-1l06pbn">
min
</code>
bound:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.runCommand(\n {\n updateZoneKeyRange : \"exampledb.collection\",\n min : { a : 0 },\n max : { a : 10 },\n zone : null\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">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">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->updateZoneKeyRange <!-- -->: <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->min <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">0</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->max <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->zone <!-- -->: <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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 range of
<code class="leafygreen-ui-1l06pbn">
{ a : 0 }
</code>
and
<code class="leafygreen-ui-1l06pbn">
{ a : 10 }
</code>
encompasses the existing
range, it is not an exact match and therefore
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.updateZoneKeyRange" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
updateZoneKeyRange
</code>
</span>
</a>
does not remove anything.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Compound Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#compound-shard-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="compound-shard-key">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Given a sharded collection
<code class="leafygreen-ui-1l06pbn">
exampledb.collection
</code>
with a shard key of
<code class="leafygreen-ui-1l06pbn">
{ a
: 1, b : 1 }
</code>
, the following operation creates a range covering the lower
bound of
<code class="leafygreen-ui-1l06pbn">
{ a: 1, b : 1 }
</code>
and an upper bound of
<code class="leafygreen-ui-1l06pbn">
{ a : 10, b : 10}
</code>
and
associates it with the
<code class="leafygreen-ui-1l06pbn">
alpha
</code>
zone:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"admin = db.getSiblingDB(\"admin\")\nadmin.runCommand(\n {\n updateZoneKeyRange : \"exampledb.collection\",\n min : { a : 1, b : 1 },\n max : { a : 10, b : 10 },\n zone : \"alpha\"\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">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">runCommand</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->updateZoneKeyRange <!-- -->: <span class="lg-highlight-string">"exampledb.collection"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->min <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->max <!-- -->: <!-- -->{ <!-- -->a <!-- -->: <span class="lg-highlight-number">10</span>, <!-- -->b <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->zone <!-- -->: <span class="lg-highlight-string">"alpha"</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><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/densify/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$densify (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-densify--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="-densify--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="#behavior-and-restrictions" target="_self">
<span>
Behavior and Restrictions
</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="pipeline">
<dt>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-densify" 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.-densify">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.1
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Creates new documents in a sequence of documents where certain values
in a field are missing.
</p>
<p class="leafygreen-ui-1kp3ins">
You can use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
to:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Fill gaps in time series data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Add missing values between groups of data.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Populate your data with a specified range of values.
</p>
</li>
</ul>
</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
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage has this syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n $densify: {\n field: <fieldname>,\n partitionByFields: [ <field>, <field> ... <field> ],\n range: {\n step: <number>,\n unit: <time>,\n bounds: < \"full\" || \"partition\" > || [ < lower bound >, < upper bound > ]\n }\n }\n}</time>"}
</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"> $densify: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> field: <fieldName>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> partitionByFields: [ <field 1>, <field 2> ... <field n> ],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> range: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> step: <number>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> unit: <time unit>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bounds: < "full" || "partition" > || [ < lower bound >, < upper bound > ]</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage takes a document with these fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:25%"/>
<col style="width:15%"/>
<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>
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="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-densify-field" target="_self">
<span>
field
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-field">
</span>
<p class="leafygreen-ui-1kp3ins">
The field to densify. The values of the specified
<code class="leafygreen-ui-1l06pbn">
field
</code>
must either be all numeric values or all dates.
</p>
<p class="leafygreen-ui-1kp3ins">
Documents that do not contain the specified
<code class="leafygreen-ui-1l06pbn">
field
</code>
continue
through the pipeline unmodified.
</p>
<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>
<p class="leafygreen-ui-1kp3ins">
For restrictions, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field-restrictions" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
field
</code>
Restrictions
<!-- -->
.
</span>
</a>
</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-densify-partition-by-fields" target="_self">
<span>
partitionByFields
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-partition-by-fields">
</span>
<p class="leafygreen-ui-1kp3ins">
The set of fields to act as the compound key to group
the documents. In the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage, each group of
documents is known as a
<em>
partition
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If you omit this field,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
uses one partition
for the entire collection.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-examples-partitions" target="_self">
<span>
Densifiction with Partitions
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For restrictions, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-partition-by-fields-restrictions" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
partitionByFields
</code>
Restrictions
<!-- -->
.
</span>
</a>
</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-densify-range" target="_self">
<span>
range
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-range">
</span>
<p class="leafygreen-ui-1kp3ins">
An object that specifies how the data is densified.
</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-densify-bounds" target="_self">
<span>
range.bounds
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-bounds">
</span>
<p class="leafygreen-ui-1kp3ins">
You can specify
<code class="leafygreen-ui-1l06pbn">
range.bounds
</code>
as either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An array:
<code class="leafygreen-ui-1l06pbn">
[ < lower bound >, < upper bound > ]
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A string: either
<code class="leafygreen-ui-1l06pbn">
"full"
</code>
or
<code class="leafygreen-ui-1l06pbn">
"partition"
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
bounds
</code>
is an array:
</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="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
adds documents spanning the range of
values within the specified bounds.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The data type for the bounds must correspond to the data type
in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
</span>
</a>
being densified.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For behavior details, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-bounds-behavior" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
range.bounds
</code>
Behavior
<!-- -->
.
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
bounds
</code>
is
<code class="leafygreen-ui-1l06pbn">
"full"
</code>
:
</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="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
adds documents spanning the full range of
values of the
<code class="leafygreen-ui-1l06pbn">
field
</code>
being densified.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
bounds
</code>
is
<code class="leafygreen-ui-1l06pbn">
"partition"
</code>
:
</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="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
adds documents to each partition,
similar to if you had run a
<code class="leafygreen-ui-1l06pbn">
full
</code>
range densification on
each partition individually.
</p>
</li>
</ul>
</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-densify-step" target="_self">
<span>
range.step
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-step">
</span>
<p class="leafygreen-ui-1kp3ins">
The amount to increment the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
</span>
</a>
value
in each document.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
creates a new document for
each
<code class="leafygreen-ui-1l06pbn">
step
</code>
between the existing documents.
</p>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-unit" target="_self">
<span>
range.unit
</span>
</a>
is specified,
<code class="leafygreen-ui-1l06pbn">
step
</code>
must be an integer. Otherwise,
<code class="leafygreen-ui-1l06pbn">
step
</code>
can be any numeric
value.
</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-densify-unit" target="_self">
<span>
range.unit
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Required if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
</span>
</a>
is a date.
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-unit">
</span>
<p class="leafygreen-ui-1kp3ins">
The unit to apply to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-step" target="_self">
<span>
step
</span>
</a>
field when
incrementing date values in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
You can specify one of the following values for
<code class="leafygreen-ui-1l06pbn">
unit
</code>
as a string:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
millisecond
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
second
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
minute
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
hour
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
day
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
week
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
month
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
quarter
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
year
</code>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For an example, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-examples-time-series" target="_self">
<span>
Densify Time Series Data
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Behavior and Restrictions
<a class="headerlink leafygreen-ui-1kepx47" href="#behavior-and-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="behavior-and-restrictions">
</div>
</a>
</h2>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-field-restrictions">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
field
</code>
Restrictions
<a class="headerlink leafygreen-ui-1kepx47" href="#field-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="field-restrictions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
For documents that contain the specified
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
errors if:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Any document in the collection has a
<code class="leafygreen-ui-1l06pbn">
field
</code>
value of type date and
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-unit" target="_self">
<span>
unit
</span>
</a>
field is not specified.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Any document in the collection has a
<code class="leafygreen-ui-1l06pbn">
field
</code>
value of type numeric
and the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-unit" target="_self">
<span>
unit
</span>
</a>
field is specified.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
field
</code>
name begins with
<code class="leafygreen-ui-1l06pbn">
$
</code>
. You must rename the field if
you want to densify it. To rename fields, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
.
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-partition-by-fields-restrictions">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
partitionByFields
</code>
Restrictions
<a class="headerlink leafygreen-ui-1kepx47" href="#partitionbyfields-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="partitionbyfields-restrictions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
errors if any field name in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-partition-by-fields" target="_self">
<span>
partitionByFields
</span>
</a>
array:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Evaluates to a non-string value.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Begins with
<code class="leafygreen-ui-1l06pbn">
$
</code>
.
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-bounds-behavior">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
range.bounds
</code>
Behavior
<a class="headerlink leafygreen-ui-1kepx47" href="#range.bounds-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="range.bounds-behavior">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-bounds" target="_self">
<span>
range.bounds
</span>
</a>
is an array:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The lower bound indicates the start value for the added
documents, irrespective of documents already in the collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The lower bound is inclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The upper bound is exclusive.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
does not filter out documents with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-densify-field" target="_self">
<span>
field
</span>
</a>
values outside of the specified
bounds.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Order of Output
<a class="headerlink leafygreen-ui-1kepx47" href="#order-of-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="order-of-output">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
does not guarantee sort order of the documents
it outputs.
</p>
<p class="leafygreen-ui-1kp3ins">
To guarantee sort order, use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sort/#mongodb-pipeline-pipe.-sort">
<code class="leafygreen-ui-1l06pbn">
$sort
</code>
</a>
on the field you want
to sort by.
</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-densify-examples-time-series">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Densify Time Series Data
<a class="headerlink leafygreen-ui-1kepx47" href="#densify-time-series-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="densify-time-series-data">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
weather
</code>
collection that contains temperature readings over
four hour intervals.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weather.insertMany( [\n {\n \"metadata\": { \"sensorId\": 5578, \"type\": \"temperature\" },\n \"timestamp\": ISODate(\"2021-05-18T00:00:00.000Z\"),\n \"temp\": 12\n },\n {\n \"metadata\": { \"sensorId\": 5578, \"type\": \"temperature\" },\n \"timestamp\": ISODate(\"2021-05-18T04:00:00.000Z\"),\n \"temp\": 11\n },\n {\n \"metadata\": { \"sensorId\": 5578, \"type\": \"temperature\" },\n \"timestamp\": ISODate(\"2021-05-18T08:00:00.000Z\"),\n \"temp\": 11\n },\n {\n \"metadata\": { \"sensorId\": 5578, \"type\": \"temperature\" },\n \"timestamp\": ISODate(\"2021-05-18T12:00:00.000Z\"),\n \"temp\": 12\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">weather</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">"metadata"</span>: <!-- -->{ <span class="lg-highlight-string">"sensorId"</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timestamp"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"temp"</span>: <span class="lg-highlight-number">12</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">"metadata"</span>: <!-- -->{ <span class="lg-highlight-string">"sensorId"</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timestamp"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T04:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"temp"</span>: <span class="lg-highlight-number">11</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">"metadata"</span>: <!-- -->{ <span class="lg-highlight-string">"sensorId"</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timestamp"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T08:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"temp"</span>: <span class="lg-highlight-number">11</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">"metadata"</span>: <!-- -->{ <span class="lg-highlight-string">"sensorId"</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-string">"type"</span>: <span class="lg-highlight-string">"temperature"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"timestamp"</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T12:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"temp"</span>: <span class="lg-highlight-number">12</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">
This example uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage to fill in the gaps
between the four-hour intervals to achieve hourly granularity for the
data points:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.weather.aggregate( [\n {\n $densify: {\n field: \"timestamp\",\n range: {\n step: 1,\n unit: \"hour\",\n bounds:[ ISODate(\"2021-05-18T00:00:00.000Z\"), ISODate(\"2021-05-18T08:00:00.000Z\") ]\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">weather</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">$densify</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-string">"timestamp"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">step</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">unit</span>: <span class="lg-highlight-string">"hour"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bounds</span>:<!-- -->[ <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span>)<!-- -->, <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T08:00:00.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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage fills in the gaps of time in between the
recorded temperatures.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
field: "timestamp"
</code>
densifies the
<code class="leafygreen-ui-1l06pbn">
timestamp
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
range:
</code>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
step: 1
</code>
increments the
<code class="leafygreen-ui-1l06pbn">
timestamp
</code>
field by 1 unit.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
unit: hour
</code>
densifies the
<code class="leafygreen-ui-1l06pbn">
timestamp
</code>
field by the hour.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
bounds: [ ISODate("2021-05-18T00:00:00.000Z"), ISODate("2021-05-18T08:00:00.000Z") ]
</code>
sets the range of time that is densified.
</p>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
In the following output, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
stage fills in the gaps of time
between the hours of
<code class="leafygreen-ui-1l06pbn">
00:00:00
</code>
and
<code class="leafygreen-ui-1l06pbn">
08:00:00
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n _id: ObjectId(\"618c207c63056cfad0ca4309\"),\n metadata: { sensorId: 5578, type: 'temperature' },\n timestamp: ISODate(\"2021-05-18T00:00:00.000Z\"),\n temp: 12\n },\n { timestamp: ISODate(\"2021-05-18T01:00:00.000Z\") },\n { timestamp: ISODate(\"2021-05-18T02:00:00.000Z\") },\n { timestamp: ISODate(\"2021-05-18T03:00:00.000Z\") },\n {\n _id: ObjectId(\"618c207c63056cfad0ca430a\"),\n metadata: { sensorId: 5578, type: 'temperature' },\n timestamp: ISODate(\"2021-05-18T04:00:00.000Z\"),\n temp: 11\n },\n { timestamp: ISODate(\"2021-05-18T05:00:00.000Z\") },\n { timestamp: ISODate(\"2021-05-18T06:00:00.000Z\") },\n { timestamp: ISODate(\"2021-05-18T07:00:00.000Z\") },\n {\n _id: ObjectId(\"618c207c63056cfad0ca430b\"),\n metadata: { sensorId: 5578, type: 'temperature' },\n timestamp: ISODate(\"2021-05-18T08:00:00.000Z\"),\n temp: 11\n }\n {\n _id: ObjectId(\"618c207c63056cfad0ca430c\"),\n metadata: { sensorId: 5578, type: 'temperature' },\n timestamp: ISODate(\"2021-05-18T12:00:00.000Z\"),\n temp: 12\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">"618c207c63056cfad0ca4309"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metadata</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'temperature'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T00:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">12</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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T01:00:00.000Z"</span>) }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T02:00:00.000Z"</span>) }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T03:00:00.000Z"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c207c63056cfad0ca430a"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metadata</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'temperature'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T04:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">11</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">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T05:00:00.000Z"</span>) }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T06:00:00.000Z"</span>) }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T07:00:00.000Z"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c207c63056cfad0ca430b"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metadata</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'temperature'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T08:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">11</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c207c63056cfad0ca430c"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metadata</span>: <!-- -->{ <span class="lg-highlight-attr">sensorId</span>: <span class="lg-highlight-number">5578</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'temperature'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">timestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-05-18T12:00:00.000Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">temp</span>: <span class="lg-highlight-number">12</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-densify-examples-partitions">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Densifiction with Partitions
<a class="headerlink leafygreen-ui-1kepx47" href="#densifiction-with-partitions" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="densifiction-with-partitions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
coffee
</code>
collection that contains data for two
varieties of coffee beans:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.coffee.insertMany( [\n {\n \"altitude\": 600,\n \"variety\": \"Arabica Typica\",\n \"score\": 68.3\n },\n {\n \"altitude\": 750,\n \"variety\": \"Arabica Typica\",\n \"score\": 69.5\n },\n {\n \"altitude\": 950,\n \"variety\": \"Arabica Typica\",\n \"score\": 70.5\n },\n {\n \"altitude\": 1250,\n \"variety\": \"Gesha\",\n \"score\": 88.15\n },\n {\n \"altitude\": 1700,\n \"variety\": \"Gesha\",\n \"score\": 95.5,\n \"price\": 1029\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">coffee</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">"altitude"</span>: <span class="lg-highlight-number">600</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"variety"</span>: <span class="lg-highlight-string">"Arabica Typica"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <span class="lg-highlight-number">68.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"> <span class="lg-highlight-string">"altitude"</span>: <span class="lg-highlight-number">750</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"variety"</span>: <span class="lg-highlight-string">"Arabica Typica"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <span class="lg-highlight-number">69.5</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">"altitude"</span>: <span class="lg-highlight-number">950</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"variety"</span>: <span class="lg-highlight-string">"Arabica Typica"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <span class="lg-highlight-number">70.5</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">"altitude"</span>: <span class="lg-highlight-number">1250</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"variety"</span>: <span class="lg-highlight-string">"Gesha"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <span class="lg-highlight-number">88.15</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">"altitude"</span>: <span class="lg-highlight-number">1700</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"variety"</span>: <span class="lg-highlight-string">"Gesha"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span>: <span class="lg-highlight-number">95.5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"price"</span>: <span class="lg-highlight-number">1029</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Densify the Full Range of Values
<a class="headerlink leafygreen-ui-1kepx47" href="#densify-the-full-range-of-values" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="densify-the-full-range-of-values">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
This example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
to densify the
<code class="leafygreen-ui-1l06pbn">
altitude
</code>
field for each coffee
<code class="leafygreen-ui-1l06pbn">
variety
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.coffee.aggregate( [\n {\n $densify: {\n field: \"altitude\",\n partitionByFields: [ \"variety\" ],\n range: {\n bounds: \"full\",\n step: 200\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">coffee</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">$densify</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-string">"altitude"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partitionByFields</span>: <!-- -->[ <span class="lg-highlight-string">"variety"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bounds</span>: <span class="lg-highlight-string">"full"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">step</span>: <span class="lg-highlight-number">200</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 example aggregation:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Partitions the documents by
<code class="leafygreen-ui-1l06pbn">
variety
</code>
to create one grouping for
<code class="leafygreen-ui-1l06pbn">
Arabica Typica
</code>
and one for
<code class="leafygreen-ui-1l06pbn">
Gesha
</code>
coffee.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specifies a
<code class="leafygreen-ui-1l06pbn">
full
</code>
range, meaning that the data is densified
across the full range of existing documents
<em>
for each partition
</em>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specifies a
<code class="leafygreen-ui-1l06pbn">
step
</code>
of
<code class="leafygreen-ui-1l06pbn">
200
</code>
, meaning new documents are created
at
<code class="leafygreen-ui-1l06pbn">
altitude
</code>
intervals of
<code class="leafygreen-ui-1l06pbn">
200
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The aggregation outputs 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: ObjectId(\"618c031814fbe03334480475\"),\n altitude: 600,\n variety: 'Arabica Typica',\n score: 68.3\n },\n {\n _id: ObjectId(\"618c031814fbe03334480476\"),\n altitude: 750,\n variety: 'Arabica Typica',\n score: 69.5\n },\n { variety: 'Arabica Typica', altitude: 800 },\n {\n _id: ObjectId(\"618c031814fbe03334480477\"),\n altitude: 950,\n variety: 'Arabica Typica',\n score: 70.5\n },\n { variety: 'Gesha', altitude: 600 },\n { variety: 'Gesha', altitude: 800 },\n { variety: 'Gesha', altitude: 1000 },\n { variety: 'Gesha', altitude: 1200 },\n {\n _id: ObjectId(\"618c031814fbe03334480478\"),\n altitude: 1250,\n variety: 'Gesha',\n score: 88.15\n },\n { variety: 'Gesha', altitude: 1400 },\n { variety: 'Gesha', altitude: 1600 },\n {\n _id: ObjectId(\"618c031814fbe03334480479\"),\n altitude: 1700,\n variety: 'Gesha',\n score: 95.5,\n price: 1029\n },\n { variety: 'Arabica Typica', altitude: 1000 },\n { variety: 'Arabica Typica', altitude: 1200 },\n { variety: 'Arabica Typica', altitude: 1400 },\n { variety: 'Arabica Typica', altitude: 1600 }\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">"618c031814fbe03334480475"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">600</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">68.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"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480476"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">750</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">69.5</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">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">800</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480477"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">950</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">70.5</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">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">600</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">800</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1000</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1200</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480478"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1250</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">88.15</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">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1400</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1600</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480479"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1700</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">95.5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1029</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">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1000</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1200</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1400</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1600</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> ]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
This image visualizes the documents created with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
:
</span>
</a>
</p>
<div class="css-y1v7l ej97su30">
<div role="button" tabindex="-1">
<div class="gatsby-image-wrapper gatsby-image-wrapper-constrained leafygreen-ui-12xaq6r" data-gatsby-image-wrapper="">
<div style="max-width:1744px;display:block">
<img alt="" aria-hidden="true" role="presentation" src="data:image/svg+xml;charset=utf-8,%3Csvg%20height='492'%20width='1744'%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="State of the coffee collection after full-range densifiction" data-main-image="" decoding="async" height="492" loading="lazy" sizes="(min-width: 1744px) 1744px, 100vw" src="/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/8131d/densification-full-range.webp" srcset="/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/54d9f/densification-full-range.webp 436w,/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/0a43f/densification-full-range.webp 872w,/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/8131d/densification-full-range.webp 1744w" style="--border-color:#C1C7C6;opacity:0" width="1744"/>
<noscript>
<img alt="State of the coffee collection after full-range densifiction" data-gatsby-image-ssr="" data-main-image="" decoding="async" height="492" loading="lazy" sizes="(min-width: 1744px) 1744px, 100vw" src="/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/8131d/densification-full-range.webp" srcset="/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/54d9f/densification-full-range.webp 436w,/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/0a43f/densification-full-range.webp 872w,/docs/manual/static/57b73dd19140d1d03bc4cd05ea6b8b0c/8131d/densification-full-range.webp 1744w" style="--border-color:#C1C7C6;opacity:0" width="1744"/>
</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="css-19pi7x2 ej97su31" style="--color:#444">
click to enlarge
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The darker squares represent the original documents in the collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The lighter squares represent the documents created with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
.
</span>
</a>
</p>
</li>
</ul>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Densify Values within Each Partition
<a class="headerlink leafygreen-ui-1kepx47" href="#densify-values-within-each-partition" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="densify-values-within-each-partition">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
This example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
</span>
</a>
to only densify gaps in the
<code class="leafygreen-ui-1l06pbn">
altitude
</code>
field within each
<code class="leafygreen-ui-1l06pbn">
variety
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.coffee.aggregate( [\n {\n $densify: {\n field: \"altitude\",\n partitionByFields: [ \"variety\" ],\n range: {\n bounds: \"partition\",\n step: 200\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">coffee</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">$densify</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">field</span>: <span class="lg-highlight-string">"altitude"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partitionByFields</span>: <!-- -->[ <span class="lg-highlight-string">"variety"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">range</span>: <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">bounds</span>: <span class="lg-highlight-string">"partition"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">step</span>: <span class="lg-highlight-number">200</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 example aggregation:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Partitions the documents by
<code class="leafygreen-ui-1l06pbn">
variety
</code>
to create one grouping for
<code class="leafygreen-ui-1l06pbn">
Arabica Typica
</code>
and one for
<code class="leafygreen-ui-1l06pbn">
Gesha
</code>
coffee.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specifies a
<code class="leafygreen-ui-1l06pbn">
partition
</code>
range, meaning that the data is densified
within each partition.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the
<code class="leafygreen-ui-1l06pbn">
Arabica Typica
</code>
partition, the range is
<code class="leafygreen-ui-1l06pbn">
600
</code>
-
<code class="leafygreen-ui-1l06pbn">
950
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For the
<code class="leafygreen-ui-1l06pbn">
Gesha
</code>
partition, the range is
<code class="leafygreen-ui-1l06pbn">
1250
</code>
-
<code class="leafygreen-ui-1l06pbn">
1700
</code>
.
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specifies a
<code class="leafygreen-ui-1l06pbn">
step
</code>
of
<code class="leafygreen-ui-1l06pbn">
200
</code>
, meaning new documents are created
at
<code class="leafygreen-ui-1l06pbn">
altitude
</code>
intervals of
<code class="leafygreen-ui-1l06pbn">
200
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The aggregation outputs 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: ObjectId(\"618c031814fbe03334480475\"),\n altitude: 600,\n variety: 'Arabica Typica',\n score: 68.3\n },\n {\n _id: ObjectId(\"618c031814fbe03334480476\"),\n altitude: 750,\n variety: 'Arabica Typica',\n score: 69.5\n },\n { variety: 'Arabica Typica', altitude: 800 },\n {\n _id: ObjectId(\"618c031814fbe03334480477\"),\n altitude: 950,\n variety: 'Arabica Typica',\n score: 70.5\n },\n {\n _id: ObjectId(\"618c031814fbe03334480478\"),\n altitude: 1250,\n variety: 'Gesha',\n score: 88.15\n },\n { variety: 'Gesha', altitude: 1450 },\n { variety: 'Gesha', altitude: 1650 },\n {\n _id: ObjectId(\"618c031814fbe03334480479\"),\n altitude: 1700,\n variety: 'Gesha',\n score: 95.5,\n price: 1029\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">"618c031814fbe03334480475"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">600</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">68.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"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480476"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">750</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">69.5</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">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">800</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480477"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">950</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Arabica Typica'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">70.5</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480478"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1250</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">88.15</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">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1450</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>, <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1650</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"618c031814fbe03334480479"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">altitude</span>: <span class="lg-highlight-number">1700</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">variety</span>: <span class="lg-highlight-string">'Gesha'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">score</span>: <span class="lg-highlight-number">95.5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">1029</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>
<p class="leafygreen-ui-1kp3ins">
This image visualizes the documents created with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
:
</span>
</a>
</p>
<div class="css-y1v7l ej97su30">
<div role="button" tabindex="-1">
<div class="gatsby-image-wrapper gatsby-image-wrapper-constrained leafygreen-ui-12xaq6r" data-gatsby-image-wrapper="">
<div style="max-width:1624px;display:block">
<img alt="" aria-hidden="true" role="presentation" src="data:image/svg+xml;charset=utf-8,%3Csvg%20height='466'%20width='1624'%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="State of the coffee collection after partition range densification" data-main-image="" decoding="async" height="466" loading="lazy" sizes="(min-width: 1624px) 1624px, 100vw" src="/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/9a463/densification-by-partition.webp" srcset="/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/fc11e/densification-by-partition.webp 406w,/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/a91d8/densification-by-partition.webp 812w,/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/9a463/densification-by-partition.webp 1624w" style="--border-color:#C1C7C6;opacity:0" width="1624"/>
<noscript>
<img alt="State of the coffee collection after partition range densification" data-gatsby-image-ssr="" data-main-image="" decoding="async" height="466" loading="lazy" sizes="(min-width: 1624px) 1624px, 100vw" src="/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/9a463/densification-by-partition.webp" srcset="/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/fc11e/densification-by-partition.webp 406w,/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/a91d8/densification-by-partition.webp 812w,/docs/manual/static/5edec880fd39c8e07681e582cbf98a13/9a463/densification-by-partition.webp 1624w" style="--border-color:#C1C7C6;opacity:0" width="1624"/>
</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="css-19pi7x2 ej97su31" style="--color:#444">
click to enlarge
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The darker squares represent the original documents in the collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The lighter squares represent the documents created with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-densify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$densify
</code>
.
</span>
</a>
</p>
</li>
</ul>
</section>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$dayOfWeek (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-dayofweek--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="-dayofweek--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">
$dayOfWeek
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-dayOfWeek" 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.-dayOfWeek">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the day of the week for a date as a number between 1
(Sunday) and 7 (Saturday).
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-dayOfWeek" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dayOfWeek
</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":"{ $dayOfWeek: <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">$dayOfWeek</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":"{ $dayOfWeek: 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">$dayOfWeek</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>
6
</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":"{ $dayOfWeek: { 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">$dayOfWeek</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>
3
</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":"{ $dayOfWeek: {\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">$dayOfWeek</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>
1
</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":"{ $dayOfWeek: 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">$dayOfWeek</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>
7
</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":"{ $dayOfWeek: {\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">$dayOfWeek</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>
6
</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":"{ $dayOfWeek: \"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">$dayOfWeek</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":"{ $dayOfWeek: 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">$dayOfWeek</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":"{ $dayOfWeek: \"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">$dayOfWeek</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>
$dayOfWeek 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 document:
</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.-dayOfWeek" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$dayOfWeek
</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=""><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="leafygreen-ui-1wr1lm6"><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.collection.estimatedDocumentCount/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.collection.estimatedDocumentCount()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.estimateddocumentcount--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.collection.estimateddocumentcount--">
</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>
<div class="leafygreen-ui-147elvs">
<p class="leafygreen-ui-1ronz74">
MongoDB with drivers
</p>
<div class="leafygreen-ui-18k5rfm">
<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. To see the equivalent
method in a MongoDB driver, see the corresponding page for your
programming language:
</p>
</div>
<div class="leafygreen-ui-zgrwqu notranslate">
<a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/csharp/current/fundamentals/crud/read-operations/count/#estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59964)">
<g clip-path="url(#clip1_1351_59964)">
<path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC">
</path>
<path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068">
</path>
<path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091">
</path>
<path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white">
</path>
<path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59964">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59964">
<rect fill="white" height="27" transform="translate(2 1.30966)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C#
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/current/usage-examples/count/" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD">
</path>
<path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD">
</path>
<path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E">
</path>
<path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD">
</path>
<path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD">
</path>
<path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD">
</path>
<path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E">
</path>
<path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD">
</path>
</svg>
<span>
Java Sync
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/node/current/usage-examples/count/" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" 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(#:R16v5qcmqn9:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R16v5qcmqn9: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=":R16v5qcmqn9: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=":R16v5qcmqn9: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>
<span>
Node.js
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/languages/python/pymongo-driver/current/read/count/#retrieve-an-estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg">
<lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257">
<stop offset="0" stop-color="#5a9fd4">
</stop>
<stop offset="1" stop-color="#306998">
</stop>
</lineargradient>
<path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R18v5qcmqn9:aa)">
</path>
<lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946">
<stop offset="0" stop-color="#ffd43b">
</stop>
<stop offset="1" stop-color="#ffe873">
</stop>
</lineargradient>
<path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R18v5qcmqn9:bb)">
</path>
<radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R18v5qcmqn9:cc" r="29.037">
<stop offset="0" stop-color="#b8b8b8" stop-opacity=".498">
</stop>
<stop offset="1" stop-color="#7f7f7f" stop-opacity="0">
</stop>
</radialgradient>
<path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R18v5qcmqn9:cc)" opacity=".444">
</path>
</svg>
<span>
PyMongo
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongoc.org/libmongoc/current/mongoc_collection_estimated_document_count.html" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59955)">
<g clip-path="url(#clip1_1351_59955)">
<path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59955">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59955">
<rect fill="white" height="27" transform="translate(2 1.30887)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/cpp/cpp-driver/upcoming/read/count/#retrieve-an-estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59959)">
<g clip-path="url(#clip1_1351_59959)">
<path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C">
</path>
<path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482">
</path>
<path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2">
</path>
<path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white">
</path>
<path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white">
</path>
<path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59959">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59959">
<rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C++
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/go/current/fundamentals/crud/read-operations/count/#estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0">
<path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z">
</path>
<g id="CXHf1q_3_">
<path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z">
</path>
<path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z">
</path>
</g>
</svg>
<span>
Go
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#estimatedDocumentCount()" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD">
</path>
<path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD">
</path>
<path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E">
</path>
<path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD">
</path>
<path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD">
</path>
<path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD">
</path>
<path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E">
</path>
<path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD">
</path>
</svg>
<span>
Java RS
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/usage-examples/count/" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R1iv5qcmqn9:paint0_linear_211_40588)">
</path>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R1iv5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29">
<stop offset="0.00343514" stop-color="#E44857">
</stop>
<stop offset="0.4689" stop-color="#C711E1">
</stop>
<stop offset="1" stop-color="#7F52FF">
</stop>
</lineargradient>
</defs>
</svg>
<span>
Kotlin Coroutine
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/languages/kotlin/kotlin-sync-driver/current/read/count/#retrieve-an-estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R1kv5qcmqn9:paint0_linear_211_40588)">
</path>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R1kv5qcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29">
<stop offset="0.00343514" stop-color="#E44857">
</stop>
<stop offset="0.4689" stop-color="#C711E1">
</stop>
<stop offset="1" stop-color="#7F52FF">
</stop>
</lineargradient>
</defs>
</svg>
<span>
Kotlin Sync
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/read/count/#retrieve-an-estimated-count" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0">
<defs>
<clippath clippathunits="userSpaceOnUse" id="a">
<path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439">
</path>
</clippath>
<clippath clippathunits="userSpaceOnUse" id="c">
<path d="M0 324h576V0H0v324z">
</path>
</clippath>
<clippath clippathunits="userSpaceOnUse" id="d">
<path d="M0 324h576V0H0v324z">
</path>
</clippath>
<radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad">
<stop offset="0" stop-color="#aeb2d5">
</stop>
<stop offset=".3" stop-color="#aeb2d5">
</stop>
<stop offset=".75" stop-color="#484c89">
</stop>
<stop offset="1" stop-color="#484c89">
</stop>
</radialgradient>
</defs>
<g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)">
</path>
</g>
<g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3">
</path>
</g>
<g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z">
</path>
<path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff">
</path>
<path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z">
</path>
<path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff">
</path>
<path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z">
</path>
<path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff">
</path>
</g>
</svg>
<span>
PHP
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/mongoid/current/reference/queries/#additional-query-methods" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg">
<defs>
<lineargradient id=":R1ov5qcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%">
<stop offset="0%" stop-color="#FB7655">
</stop>
<stop offset="0%" stop-color="#FB7655">
</stop>
<stop offset="41%" stop-color="#E42B1E">
</stop>
<stop offset="99%" stop-color="#900">
</stop>
<stop offset="100%" stop-color="#900">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%">
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="99%" stop-color="#911209">
</stop>
<stop offset="100%" stop-color="#911209">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%">
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="99%" stop-color="#911209">
</stop>
<stop offset="100%" stop-color="#911209">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="23%" stop-color="#E57252">
</stop>
<stop offset="46%" stop-color="#DE3B20">
</stop>
<stop offset="99%" stop-color="#A60003">
</stop>
<stop offset="100%" stop-color="#A60003">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="23%" stop-color="#E4714E">
</stop>
<stop offset="56%" stop-color="#BE1A0D">
</stop>
<stop offset="99%" stop-color="#A80D00">
</stop>
<stop offset="100%" stop-color="#A80D00">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="18%" stop-color="#E46342">
</stop>
<stop offset="40%" stop-color="#C82410">
</stop>
<stop offset="99%" stop-color="#A80D00">
</stop>
<stop offset="100%" stop-color="#A80D00">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="54%" stop-color="#C81F11">
</stop>
<stop offset="99%" stop-color="#BF0905">
</stop>
<stop offset="100%" stop-color="#BF0905">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="31%" stop-color="#DE4024">
</stop>
<stop offset="99%" stop-color="#BF190B">
</stop>
<stop offset="100%" stop-color="#BF190B">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%">
<stop offset="0%" stop-color="#BD0012">
</stop>
<stop offset="0%" stop-color="#BD0012">
</stop>
<stop offset="7%" stop-color="#FFF">
</stop>
<stop offset="17%" stop-color="#FFF">
</stop>
<stop offset="27%" stop-color="#C82F1C">
</stop>
<stop offset="33%" stop-color="#820C01">
</stop>
<stop offset="46%" stop-color="#A31601">
</stop>
<stop offset="72%" stop-color="#B31301">
</stop>
<stop offset="99%" stop-color="#E82609">
</stop>
<stop offset="100%" stop-color="#E82609">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%">
<stop offset="0%" stop-color="#8C0C01">
</stop>
<stop offset="0%" stop-color="#8C0C01">
</stop>
<stop offset="54%" stop-color="#990C00">
</stop>
<stop offset="99%" stop-color="#A80D0E">
</stop>
<stop offset="100%" stop-color="#A80D0E">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%">
<stop offset="0%" stop-color="#7E110B">
</stop>
<stop offset="0%" stop-color="#7E110B">
</stop>
<stop offset="99%" stop-color="#9E0C00">
</stop>
<stop offset="100%" stop-color="#9E0C00">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%">
<stop offset="0%" stop-color="#79130D">
</stop>
<stop offset="0%" stop-color="#79130D">
</stop>
<stop offset="99%" stop-color="#9E120B">
</stop>
<stop offset="100%" stop-color="#9E120B">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%">
<stop offset="0%" stop-color="#8B2114">
</stop>
<stop offset="0%" stop-color="#8B2114">
</stop>
<stop offset="43%" stop-color="#9E100A">
</stop>
<stop offset="99%" stop-color="#B3100C">
</stop>
<stop offset="100%" stop-color="#B3100C">
</stop>
</lineargradient>
<lineargradient id=":R1ov5qcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%">
<stop offset="0%" stop-color="#B31000">
</stop>
<stop offset="0%" stop-color="#B31000">
</stop>
<stop offset="44%" stop-color="#910F08">
</stop>
<stop offset="99%" stop-color="#791C12">
</stop>
<stop offset="100%" stop-color="#791C12">
</stop>
</lineargradient>
<radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R1ov5qcmqn9:m" r="69.573%">
<stop offset="0%" stop-color="#A80D00">
</stop>
<stop offset="0%" stop-color="#A80D00">
</stop>
<stop offset="99%" stop-color="#7E0E08">
</stop>
<stop offset="100%" stop-color="#7E0E08">
</stop>
</radialgradient>
<radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R1ov5qcmqn9:n" r="88.386%">
<stop offset="0%" stop-color="#A30C00">
</stop>
<stop offset="0%" stop-color="#A30C00">
</stop>
<stop offset="99%" stop-color="#800E08">
</stop>
<stop offset="100%" stop-color="#800E08">
</stop>
</radialgradient>
</defs>
<path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R1ov5qcmqn9:a)">
</path>
<path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R1ov5qcmqn9:b)">
</path>
<path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R1ov5qcmqn9:c)">
</path>
<path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R1ov5qcmqn9:d)">
</path>
<path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R1ov5qcmqn9:e)">
</path>
<path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R1ov5qcmqn9:f)">
</path>
<path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R1ov5qcmqn9:g)">
</path>
<path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R1ov5qcmqn9:h)">
</path>
<path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF">
</path>
<path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R1ov5qcmqn9:i)">
</path>
<path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R1ov5qcmqn9:j)">
</path>
<path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R1ov5qcmqn9:k)">
</path>
<path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R1ov5qcmqn9:l)">
</path>
<path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209">
</path>
<path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R1ov5qcmqn9:m)">
</path>
<path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R1ov5qcmqn9:n)">
</path>
<path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R1ov5qcmqn9:o)">
</path>
<path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R1ov5qcmqn9:p)">
</path>
</svg>
<span>
Mongoid
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/rust/current/usage-examples/count/" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_5454_14623)">
<path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black">
</path>
<path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
</path>
</g>
<defs>
<clippath id="clip0_5454_14623">
<rect fill="black" height="30" width="30">
</rect>
</clippath>
</defs>
</svg>
<span>
Rust
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongo-scala-driver/org/mongodb/scala/MongoCollection.html#estimatedDocumentCount():org.mongodb.scala.SingleObservable[Long]" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg">
<defs>
<lineargradient id=":R1sv5qcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%">
<stop offset="0%" stop-color="#CD413F">
</stop>
<stop offset="75.091%" stop-color="#CD4543">
</stop>
<stop offset="100%" stop-color="#D04543">
</stop>
</lineargradient>
</defs>
<g fill="none" fill-rule="nonzero">
<path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818">
</path>
<g fill="url(#:R1sv5qcmqn9:aaa)" transform="translate(13)">
<path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843">
</path>
</g>
</g>
</svg>
<span>
Scala
</span>
</a>
</div>
<button class="leafygreen-ui-ki2t97">
Show all
<svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.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 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</button>
</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.collection.estimatedDocumentCount(options)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.estimatedDocumentCount" 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.collection.estimatedDocumentCount">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Returns the count of all documents in a collection or view.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.estimatedDocumentCount( <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-property">collection</span>.<span class="lg-highlight-title lg-highlight-function">estimatedDocumentCount</span>( <<!-- -->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>
<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>
options
</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. Extra options that affect the count behavior.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
options
</code>
document can contain the following:
</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">
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>
Optional. The maximum amount of time to allow the count to run.
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Mechanics
<a class="headerlink leafygreen-ui-1kepx47" href="#mechanics" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="mechanics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
does not take a query
filter and instead uses metadata to return the count for a collection.
</p>
<p class="leafygreen-ui-1kp3ins">
For a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
view
<!-- -->
:
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
There is no metadata.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The document count is calculated by executing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation
pipeline
</a>
in the view definition.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
There is no fast estimated document count.
</p>
</li>
</ul>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sharded Clusters
<a class="headerlink leafygreen-ui-1kepx47" href="#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="sharded-clusters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
On a sharded cluster, the resulting count will not correctly filter out
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-orphaned-document">
orphaned documents
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-estimated-document-count-unclean-shutdown">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unclean Shutdown
<a class="headerlink leafygreen-ui-1kepx47" href="#unclean-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="unclean-shutdown">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
This section only applies to collections.
</p>
<p class="leafygreen-ui-1kp3ins">
After an unclean shutdown, the count may be incorrect.
</p>
<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,
<!-- -->
count
<!-- -->
statistics reported by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
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>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Client Disconnection
<a class="headerlink leafygreen-ui-1kepx47" href="#client-disconnection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-disconnection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 4.2, if the client that issued
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
disconnects before the operation completes, MongoDB marks
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
for termination using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/killOp/#mongodb-dbcommand-dbcmd.killOp">
<code class="leafygreen-ui-1l06pbn">
killOp
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Count and Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#count-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="count-and-transactions">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
in a transaction, the resulting count will
not filter out any uncommitted
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
multi-document transactions
<!-- -->
.
</a>
</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 uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.estimatedDocumentCount" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</span>
</a>
to retrieve the count of
all documents in the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.estimatedDocumentCount({})","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">orders</span>.<span class="lg-highlight-title lg-highlight-function">estimatedDocumentCount</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.countDocuments/#mongodb-method-db.collection.countDocuments">
<code class="leafygreen-ui-1l06pbn">
db.collection.countDocuments()
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count">
<code class="leafygreen-ui-1l06pbn">
count
</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/collStats/#std-label-collstat-count">
collStats pipeline stage with the count
</a>
option
</p>
</li>
</ul>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$trim (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-trim--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="-trim--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">
$trim
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-trim" 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.-trim">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Removes whitespace characters, including null, or the specified
characters from the beginning and end of a string.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</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":"{ $trim: { input: <string>, chars: <string> } }","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">$trim</span>: <!-- -->{ <span class="lg-highlight-attr">input</span>: <<!-- -->string<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">chars</span>: <<!-- -->string<!-- -->> <!-- -->} }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</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="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
input
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The string to trim. The argument 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 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">
chars
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Optional. The character(s) to trim from
<code class="leafygreen-ui-1l06pbn">
input
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The argument 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 string. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</code>
</span>
</a>
operator breaks down the string into
individual UTF
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="http://www.unicode.org/glossary/#code_point" rel="noopener noreferrer">
<span>
code point
</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 trim from
<code class="leafygreen-ui-1l06pbn">
input
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If unspecified,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</code>
</span>
</a>
removes whitespace
characters, including the null character. For the list of
whitespace characters, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-trim-white-space" target="_self">
<span>
Whitespace Characters
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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/ltrim/#mongodb-expression-exp.-ltrim">
<code class="leafygreen-ui-1l06pbn">
$ltrim
</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/rtrim/#mongodb-expression-exp.-rtrim">
<code class="leafygreen-ui-1l06pbn">
$rtrim
</code>
</a>
</p>
</li>
</ul>
</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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
By default,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</code>
</span>
</a>
removes whitespace characters,
including the null character:
</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>
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">
{ $trim: { input: " \n good bye \t " } }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"good bye"
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can override the default characters to trim using the
<code class="leafygreen-ui-1l06pbn">
chars
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following trims any
<code class="leafygreen-ui-1l06pbn">
g
</code>
and
<code class="leafygreen-ui-1l06pbn">
e
</code>
from the start and end of the input. Since the input starts with a
whitespace, neither character can be trimmed from the start of the
string.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:87%"/>
<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">
{ $trim: { input: " ggggoodbyeeeee", chars: "ge" } }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
" ggggoodby"
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If overriding the default characters to trim, you can explicitly
include the whitespace character(s) to trim in the
<code class="leafygreen-ui-1l06pbn">
chars
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
For example, the following trims any space,
<code class="leafygreen-ui-1l06pbn">
g
</code>
,
<code class="leafygreen-ui-1l06pbn">
e
</code>
from the
start and end of the input.
</p>
<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>
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">
{ $trim: { input: " ggggoodbyeeeee", chars: " ge" } }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
"oodby"
</code>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-trim-white-space">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Whitespace Characters
<a class="headerlink leafygreen-ui-1kepx47" href="#whitespace-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="whitespace-characters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</code>
</span>
</a>
removes the following whitespaces,
including the null character:
</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>
Unicode
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Escape sequence
</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>
U+0000
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
'0'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Null character
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+0020
</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>
Space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+0009
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
't'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Horizontal tab
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+000A
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
'n'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Line feed/new line
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+000B
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
'v'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Vertical tab
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+000C
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
'f'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Form feed
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+000D
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
'r'
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Carriage return
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+00A0
</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>
Non-breaking space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+1680
</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>
Ogham space mark
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2000
</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>
En quad
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2001
</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>
Em quad
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2002
</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>
En space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2003
</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>
Em space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2004
</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>
Three-per-em space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2005
</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>
Four-per-em space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2006
</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>
Six-per-em space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2007
</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>
Figure space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2008
</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>
Punctuation space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+2009
</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>
Thin space
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
U+200A
</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>
Hair space
</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">
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\" : \"ABC1\", quarter: \"13Q1\", \"description\" : \" product 1\" }\n{ \"_id\" : 2, \"item\" : \"ABC2\", quarter: \"13Q4\", \"description\" : \"product 2 \\n The product is in stock. \\n\\n \" }\n{ \"_id\" : 3, \"item\" : \"XYZ1\", quarter: \"14Q2\", \"description\" : null }","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">quarter</span>: <span class="lg-highlight-string">"13Q1"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">" product 1"</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">quarter</span>: <span class="lg-highlight-string">"13Q4"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 2 </span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string"> The product is in stock. </span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string"> "</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">"XYZ1"</span>, <span class="lg-highlight-attr">quarter</span>: <span class="lg-highlight-string">"14Q2"</span>, <span class="lg-highlight-string">"description"</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>
<p class="leafygreen-ui-1kp3ins">
The following operation uses the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-trim" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$trim
</code>
</span>
</a>
operator to remove
leading and trailing whitespaces from the
<code class="leafygreen-ui-1l06pbn">
description
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.inventory.aggregate([\n { $project: { item: 1, description: { $trim: { input: \"$description\" } } } }\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">$project</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">description</span>: <!-- -->{ <span class="lg-highlight-attr">$trim</span>: <!-- -->{ <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$description"</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, \"item\" : \"ABC1\", \"description\" : \"product 1\" }\n{ \"_id\" : 3, \"item\" : \"XYZ1\", \"description\" : null }\n{ \"_id\" : 2, \"item\" : \"ABC2\", \"description\" : \"product 2 \\n The product is in stock.\" }","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">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 1"</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">"XYZ1"</span>, <span class="lg-highlight-string">"description"</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">2</span>, <span class="lg-highlight-string">"item"</span> <!-- -->: <span class="lg-highlight-string">"ABC2"</span>, <span class="lg-highlight-string">"description"</span> <!-- -->: <span class="lg-highlight-string">"product 2 </span><span class="lg-highlight-string">\n</span><span class="lg-highlight-string"> The product is in stock."</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/core/replica-set-sync/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Replica Set Data Synchronization
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-data-synchronization" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-data-synchronization">
</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="#initial-sync" target="_self">
<span>
Initial Sync
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#replication" target="_self">
<span>
Replication
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
To maintain up-to-date copies of the shared data set,
secondary members of a replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sync">
sync
</a>
or replicate data from a
<!-- -->
source member
<!-- -->
. MongoDB uses two forms of data synchronization:
initial sync to populate new members
with the full data set, and replication to apply ongoing changes to the
entire data set.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-initial-sync">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Initial Sync
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-sync" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="initial-sync">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Initial sync copies all the data from the
<!-- -->
source member
<!-- -->
of the replica set to
a
<!-- -->
destination member
<!-- -->
. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-initial-sync-source-selection" target="_self">
<span>
Initial Sync Source Selection
</span>
</a>
for
more information on
<!-- -->
source member
<!-- -->
selection criteria.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
local
</code>
database stores the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
data that the initial
sync process uses. Ensure the
<!-- -->
destination member
<!-- -->
has enough space in the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database to store the oplog data for the initial sync process to
complete.
</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">
During the initial sync, MongoDB truncates the oplog on the
<!-- -->
destination member
<!-- -->
. This
oplog truncation can impact processes, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change streams
</a>
, that depend on oplog data.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
You can specify the preferred initial sync source using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
parameter. This parameter can
only be specified 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>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.2, initial syncs can be
<em>
logical
</em>
or
<em>
file copy
based
</em>
.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-initial-sync-logical">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Logical Initial Sync Process
<a class="headerlink leafygreen-ui-1kepx47" href="#logical-initial-sync-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="logical-initial-sync-process">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When you perform a logical initial sync, MongoDB:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Clones all databases except the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/local-database/#std-label-replica-set-local-database">
local
</a>
database. To clone, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
scans every collection in each
<!-- -->
source member
<!-- -->
database and inserts all data into its own copies of these
collections.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Builds all collection indexes as the documents are copied for each
collection.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Pulls newly added oplog records during the data copy. Ensure that the
<!-- -->
destination member
<!-- -->
has enough disk space in the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database to temporarily store these oplog records for the duration of
this data copy stage.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Applies all changes to the data set. Using the oplog from the
<!-- -->
source member
<!-- -->
, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
updates its data set to reflect
the current state of the replica set.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
When the initial sync finishes, the member transitions from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.STARTUP2">
<code class="leafygreen-ui-1l06pbn">
STARTUP2
</code>
</a>
to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
To perform an initial sync, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/resync-replica-set-member/#std-label-resync-replica-member">
Resync a Member of a Self-Managed Replica Set
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-initial-sync-file-copy-based">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
File Copy Based Initial Sync
<a class="headerlink leafygreen-ui-1kepx47" href="#file-copy-based-initial-sync" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="file-copy-based-initial-sync">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<em>
Available in MongoDB Enterprise only.
</em>
</p>
<p class="leafygreen-ui-1kp3ins">
File copy based initial sync runs the initial sync process by copying
and moving files on the file system. This sync method can be faster than
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-initial-sync-logical" target="_self">
<span>
logical initial sync
<!-- -->
.
</span>
</a>
</p>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
File copy based initial sync may cause inaccurate counts
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
After file copy based initial sync completes, if you run the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.count/#mongodb-method-db.collection.count">
<code class="leafygreen-ui-1l06pbn">
count()
</code>
</a>
method without a query predicate, the
count of documents returned may be inaccurate.
</p>
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
count
</code>
method without a query predicate looks like this:
<code class="leafygreen-ui-1l06pbn">
db.<collection>.count()
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.count/#std-label-count-method-behavior-query-predicate">
Inaccurate Counts Without Query Predicate
<!-- -->
.
</a>
</p>
</div>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Enable File Copy Based Initial Sync
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-file-copy-based-initial-sync" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-file-copy-based-initial-sync">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
To enable file copy based initial sync, set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncMethod">
<code class="leafygreen-ui-1l06pbn">
initialSyncMethod
</code>
</a>
parameter to
<code class="leafygreen-ui-1l06pbn">
fileCopyBased
</code>
on the
<!-- -->
destination member
<!-- -->
for the initial sync. This parameter can only be set
at startup.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
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>
</h4>
<p class="leafygreen-ui-1kp3ins">
File copy based initial sync replaces the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database of the
<!-- -->
destination member
<!-- -->
with the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database of the source member when
syncing.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
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>
</h4>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
During a file copy based initial sync:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot run backups on either the
<!-- -->
source member
<!-- -->
or the
<!-- -->
destination member
<!-- -->
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You cannot write to the
<code class="leafygreen-ui-1l06pbn">
local
</code>
database on the
<!-- -->
destination member
<!-- -->
.
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can only run an initial sync from one
<!-- -->
source member
<!-- -->
at a time.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When using the encrypted storage engine, MongoDB uses the
<!-- -->
source member
<!-- -->
key to encrypt the destination.
</p>
</li>
</ul>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initial Sync on NVMe Clusters
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-sync-on-nvme-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="initial-sync-on-nvme-clusters">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
You must perform an initial sync on clusters that use the local
Non-Volatile Memory Express (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-NVMe">
NVMe
</a>
) SSD storage option, including
if you're using Atlas
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/cluster-autoscaling/#std-label-cluster-autoscaling" target="_self">
<span>
auto-scaling
</span>
</a>
. Atlas
NVMe clusters auto-scale to the next higher tier when 90% of the storage
space is full. An initial sync takes longer to complete compared to
subsequent syncs, and reduces the performance of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
from which the data is read.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-init-sync-retry">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Fault Tolerance
<a class="headerlink leafygreen-ui-1kepx47" href="#fault-tolerance" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fault-tolerance">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If a
<!-- -->
destination member
<!-- -->
performing initial sync encounters a persistent network
error during the sync process, the
<!-- -->
destination member
<!-- -->
restarts the initial sync
process from the beginning.
</p>
<p class="leafygreen-ui-1kp3ins">
A
<!-- -->
destination member
<!-- -->
performing initial sync can attempt to resume the sync process
if interrupted by a temporary network error, collection drop, or
collection rename.
</p>
<p class="leafygreen-ui-1kp3ins">
By default, the
<!-- -->
destination member
<!-- -->
tries to resume initial sync for 24 hours.
You can use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncTransientErrorRetryPeriodSeconds">
<code class="leafygreen-ui-1l06pbn">
initialSyncTransientErrorRetryPeriodSeconds
</code>
</a>
server parameter to control the amount of time the
<!-- -->
destination member
<!-- -->
attempts to
resume initial sync. If the
<!-- -->
destination member
<!-- -->
cannot successfully resume the
initial sync process during the configured time period, it selects a new
healthy
<!-- -->
source member
<!-- -->
from the replica set and restarts the initial
synchronization process from the beginning.
</p>
<p class="leafygreen-ui-1kp3ins">
The secondary attempts to restart the initial sync up to
<code class="leafygreen-ui-1l06pbn">
10
</code>
times
before returning a fatal error.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-initial-sync-source-selection">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Initial Sync Source Selection
<a class="headerlink leafygreen-ui-1kepx47" href="#initial-sync-source-selection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="initial-sync-source-selection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Initial sync source selection depends on the value 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>
startup parameter
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
:
</a>
</p>
<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/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
set to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primary">
<code class="leafygreen-ui-1l06pbn">
primary
</code>
</a>
(default if
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.chainingAllowed">
<code class="leafygreen-ui-1l06pbn">
chainingAllowed
</code>
</a>
is disabled), select the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
as the
<!-- -->
source member
<!-- -->
. If the primary is unavailable or unreachable, log
an error and periodically check for primary availability.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
set to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-primaryPreferred">
<code class="leafygreen-ui-1l06pbn">
primaryPreferred
</code>
</a>
(default for voting replica set
members), attempt to select the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
as the
<!-- -->
source member
<!-- -->
. If
the primary is unavailable or unreachable, perform sync
<!-- -->
source member
<!-- -->
selection from the remaining replica set members.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For all other supported read modes, perform sync
<!-- -->
source member
<!-- -->
selection
from the
<!-- -->
destination members
<!-- -->
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Members performing initial
<!-- -->
source member
<!-- -->
selection make two passes through
the list of all replica set members:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-13">
<div aria-label="Tabs to describe usage of firstpass/second pass" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_wv9redkg5" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_qxlz8m4w8" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
First Pass
</div>
</button>
<button aria-controls="_5ipbaxrx7" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_lmwxgmwsg" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Second Pass
</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="_thu6jzkz2" class="" id="_pbx9hziun" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The member applies the following criteria to each replica
set member when making the first pass for selecting a
initial
<!-- -->
source member
<!-- -->
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
replication state.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be online and reachable.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondaryPreferred">
<code class="leafygreen-ui-1l06pbn">
secondaryPreferred
</code>
</a>
,
the
<!-- -->
source member
<!-- -->
<em>
must
</em>
be a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.hidden">
<code class="leafygreen-ui-1l06pbn">
visible
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be within
<code class="leafygreen-ui-1l06pbn">
30
</code>
seconds of the newest
oplog entry on the primary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.buildIndexes">
<code class="leafygreen-ui-1l06pbn">
builds indexes
</code>
</a>
, the
<!-- -->
source member
<!-- -->
<em>
must
</em>
build indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<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>
in
replica set elections, the
<!-- -->
source member
<!-- -->
<em>
must
</em>
also vote.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member is
<em>
not
</em>
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs">
<code class="leafygreen-ui-1l06pbn">
delayed member
</code>
</a>
, the
<!-- -->
source member
<!-- -->
<em>
must not
</em>
be delayed.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<em>
is
</em>
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs">
<code class="leafygreen-ui-1l06pbn">
delayed member
</code>
</a>
, the
<!-- -->
source member
<!-- -->
must have a shorter
configured delay.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be faster than
the current best sync source.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If no candidate
<!-- -->
source member
<!-- -->
remains after the first pass,
the member performs a second pass with relaxed criteria.
See
<span class="guilabel css-h15tq0">
Sync Source Selection (Second Pass)
</span>
.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_uz5fgtauy" class="leafygreen-ui-38lglc" id="_fn8wrm1ka" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The member applies the following criteria to each replica
set member when making the second pass for selecting a
initial
<!-- -->
source member
<!-- -->
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
replication
state.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be online and reachable.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#mongodb-readmode-secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
, the
<!-- -->
source member
<!-- -->
<em>
must
</em>
be a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.buildIndexes">
<code class="leafygreen-ui-1l06pbn">
builds indexes
</code>
</a>
, the
<!-- -->
source member
<!-- -->
must
build indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be faster than
the current best sync source.
</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the
<!-- -->
destination member
<!-- -->
cannot select a
<!-- -->
source member
<!-- -->
after two passes, it
logs an error and waits
<code class="leafygreen-ui-1l06pbn">
1
</code>
second before restarting the selection
process. 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>
can restart the initial
sync source selection process up to
<code class="leafygreen-ui-1l06pbn">
10
</code>
times before exiting with an
error.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Oplog Window
<a class="headerlink leafygreen-ui-1kepx47" href="#oplog-window" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="oplog-window">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog-window">
oplog window
</a>
must be long enough so that a
<!-- -->
destination member
<!-- -->
can fetch
any new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
entries that occur between the start and end of
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-initial-sync-logical" target="_self">
<span>
Logical Initial Sync Process
</span>
</a>
.
If the window isn't long enough, there is a risk that some entries may
fall off the
<code class="leafygreen-ui-1l06pbn">
oplog
</code>
before the
<!-- -->
destination member
<!-- -->
can apply them.
</p>
<p class="leafygreen-ui-1kp3ins">
It is recommended that you size the
<code class="leafygreen-ui-1l06pbn">
oplog
</code>
for additional time to fetch any
new
<code class="leafygreen-ui-1l06pbn">
oplog
</code>
entries. This allows for changes that may occur during initial
syncs.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-replica-set-oplog-sizing">
Oplog Size
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-replication">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Replication
<a class="headerlink leafygreen-ui-1kepx47" href="#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="replication">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Destination members
<!-- -->
replicate data continuously after the initial sync.
<!-- -->
Destination members
<!-- -->
copy the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-replica-set-oplog">
oplog
</a>
from
the
<!-- -->
source member
<!-- -->
and apply these operations in an asynchronous
process.
</p>
<p class="leafygreen-ui-1kp3ins">
Destination members
<!-- -->
automatically change their
<!-- -->
source member
<!-- -->
as needed
based on changes in the ping time and state of other members'
replication. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-replication-sync-source-selection" target="_self">
<span>
Replication Sync Source Selection
</span>
</a>
for more information on
<!-- -->
source member
<!-- -->
selection criteria.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-streaming-replication">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Streaming Replication
<a class="headerlink leafygreen-ui-1kepx47" href="#streaming-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="streaming-replication">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Source members
<!-- -->
send a continuous stream
of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-oplog/#std-label-replica-set-oplog">
oplog
</a>
entries to their
<!-- -->
destination members
<!-- -->
.
Streaming replication mitigates replication lag in high-load and
high-latency networks. It also:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Reduces staleness for reads from secondaries.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Reduces risk of losing write operations with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
w: 1
</a>
due to
primary failover.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Reduces latency on write operations 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>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
w: >1
</a>
(that is, any write concern that
requires waiting for replication).
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.oplogFetcherUsesExhaust">
<code class="leafygreen-ui-1l06pbn">
oplogFetcherUsesExhaust
</code>
</a>
startup parameter to disable
streaming replication and using the older replication behavior.
Set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.oplogFetcherUsesExhaust">
<code class="leafygreen-ui-1l06pbn">
oplogFetcherUsesExhaust
</code>
</a>
parameter to
<code class="leafygreen-ui-1l06pbn">
false
</code>
only if
there are any resource constraints on the
<!-- -->
source member
<!-- -->
or if you wish
to limit MongoDB's usage of network bandwidth for replication.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-internals-multi-threaded-replication">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Multithreaded Replication
<a class="headerlink leafygreen-ui-1kepx47" href="#multithreaded-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="multithreaded-replication">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB applies write operations in batches using multiple threads to
improve concurrency. MongoDB groups batches by document ID (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
) and simultaneously applies each group of
operations using a different thread. MongoDB always applies write
operations to a given document in their original write order.
</p>
<p class="leafygreen-ui-1kp3ins">
Read operations that
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-replica-set-read-preference">
target secondaries
</a>
and are
configured with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern">
read concern
</a>
level of
<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-majority/#mongodb-readconcern-readconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
"majority"
</code>
</a>
read from
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/wiredtiger/#std-label-storage-wiredtiger">
WiredTiger
</a>
snapshot of the data if the read
takes place on a secondary where replication batches are being applied.
</p>
<p class="leafygreen-ui-1kp3ins">
Reading from a snapshot guarantees a consistent view of the
data, and allows the read to occur simultaneously with the ongoing
replication without the need for a lock. As a result, secondary reads
requiring these read concern levels no longer need to wait for
replication batches to be applied, and can be handled as they are
received.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Flow Control
<a class="headerlink leafygreen-ui-1kepx47" href="#flow-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="flow-control">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Administrators can limit the rate at which
the primary applies its writes with the goal of keeping the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.optimes.lastCommittedOpTime">
<code class="leafygreen-ui-1l06pbn">
majority
committed
</code>
</a>
lag under
a configurable maximum value
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.flowControlTargetLagSeconds">
<code class="leafygreen-ui-1l06pbn">
flowControlTargetLagSeconds
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
By default, flow control is
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.enableFlowControl">
<code class="leafygreen-ui-1l06pbn">
enabled
</code>
.
</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">
For flow control to engage, the replica set/sharded cluster must
have:
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion (fCV)
</a>
of
<code class="leafygreen-ui-1l06pbn">
4.2
</code>
and read concern
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.enableMajorityReadConcern">
<code class="leafygreen-ui-1l06pbn">
majority enabled
</code>
</a>
. That is, enabled flow
control has no effect if fCV is not
<code class="leafygreen-ui-1l06pbn">
4.2
</code>
or if read concern
majority is disabled.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/troubleshoot-replica-sets/#std-label-flow-control">
Flow Control
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-replication-sync-source-selection">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Replication Sync Source Selection
<a class="headerlink leafygreen-ui-1kepx47" href="#replication-sync-source-selection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="replication-sync-source-selection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Replication
<!-- -->
source member
<!-- -->
selection depends on the replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.chainingAllowed">
<code class="leafygreen-ui-1l06pbn">
chaining
</code>
</a>
setting:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
With chaining enabled (default), perform
<!-- -->
source member
<!-- -->
selection from
the
<!-- -->
destination members
<!-- -->
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
With chaining disabled, select the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
as the
<!-- -->
source member
<!-- -->
.
If the primary is unavailable or unreachable, log an error and
periodically check for primary availability.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Members performing replication
<!-- -->
source member
<!-- -->
selection make two passes
through the list of all replica set members:
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-20">
<div aria-label="Tabs to describe usage of firstpass/second pass" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_lrdl3noww" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_hs9c7ptbz" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
First Pass
</div>
</button>
<button aria-controls="_nsfm2ygzw" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_nyu4kv1az" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Second Pass
</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="_psukhrdtw" class="" id="_9aicogtqx" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The member applies the following criteria to each replica
set member when making the first pass for selecting a
<!-- -->
source member
<!-- -->
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
replication state.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be online and reachable.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
have newer oplog entries than the member.
That is, the
<!-- -->
source member
<!-- -->
must be
<em>
ahead
</em>
of the member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.hidden">
<code class="leafygreen-ui-1l06pbn">
visible
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be within
<code class="leafygreen-ui-1l06pbn">
30
</code>
seconds of the newest
oplog entry on the primary.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.buildIndexes">
<code class="leafygreen-ui-1l06pbn">
builds indexes
</code>
</a>
, the
<!-- -->
source member
<!-- -->
<em>
must
</em>
build indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<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>
in
replica set elections, the
<!-- -->
source member
<!-- -->
<em>
must
</em>
also vote.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member is
<em>
not
</em>
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs">
<code class="leafygreen-ui-1l06pbn">
delayed member
</code>
</a>
, the
<!-- -->
source member
<!-- -->
<em>
must not
</em>
be delayed.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<em>
is
</em>
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs">
<code class="leafygreen-ui-1l06pbn">
delayed member
</code>
</a>
, the
<!-- -->
source member
<!-- -->
must have a shorter
configured delay.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be faster than the current best sync source.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If no candidate
<!-- -->
source members
<!-- -->
remain after the first pass,
the member performs a second pass with relaxed criteria.
See the
<span class="guilabel css-h15tq0">
Sync Source Selection (Second Pass)
</span>
.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_7ybluv7ud" class="leafygreen-ui-38lglc" id="_jrojriskj" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The member applies the following criteria to each replica
set member when making the second pass for selecting a
<!-- -->
source member
<!-- -->
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.PRIMARY">
<code class="leafygreen-ui-1l06pbn">
PRIMARY
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
replication
state.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be online and reachable.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the member
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.members-n-.buildIndexes">
<code class="leafygreen-ui-1l06pbn">
builds indexes
</code>
</a>
, the
<!-- -->
source member
<!-- -->
must
build indexes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<!-- -->
source member
<!-- -->
<em>
must
</em>
be faster than the current best sync source.
</p>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the member cannot select a sync source after two passes, it logs an
error and waits
<code class="leafygreen-ui-1l06pbn">
1
</code>
second before restarting the selection process.
</p>
<p class="leafygreen-ui-1kp3ins">
The number of times a
<!-- -->
source member
<!-- -->
can be changed per hour is
configurable by setting the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.maxNumSyncSourceChangesPerHour">
<code class="leafygreen-ui-1l06pbn">
maxNumSyncSourceChangesPerHour
</code>
</a>
parameter.
</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 startup parameter
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.initialSyncSourceReadPreference">
<code class="leafygreen-ui-1l06pbn">
initialSyncSourceReadPreference
</code>
</a>
takes
precedence over the replica set's
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.chainingAllowed">
<code class="leafygreen-ui-1l06pbn">
settings.chainingAllowed
</code>
</a>
setting
when selecting an initial sync
<!-- -->
source member
<!-- -->
. After a replica set member
successfully performs initial sync, it defers to the value of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-configuration/#mongodb-rsconf-rsconf.settings.chainingAllowed">
<code class="leafygreen-ui-1l06pbn">
chainingAllowed
</code>
</a>
when selecting a
<!-- -->
source member
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-replica-set-initial-sync-source-selection" target="_self">
<span>
Initial Sync Source Selection
</span>
</a>
for more
information on initial sync source selection.
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$concatArrays (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-concatarrays--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="-concatarrays--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">
$concatArrays
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-concatArrays" 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.-concatArrays">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Concatenates arrays to return the concatenated array.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-concatArrays" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$concatArrays
</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":"{ $concatArrays: [ <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">$concatArrays</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
<code class="leafygreen-ui-1l06pbn">
<array>
</code>
expressions 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 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>
<p class="leafygreen-ui-1kp3ins">
If any 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.-concatArrays" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$concatArrays
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</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>
<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":"{ $concatArrays: [\n [ \"hello\", \" \"], [ \"world\" ]\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">$concatArrays</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <span class="lg-highlight-string">"hello"</span>, <span class="lg-highlight-string">" "</span>]<!-- -->, <!-- -->[ <span class="lg-highlight-string">"world"</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ \"hello\", \" \", \"world\" ]","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-string">"hello"</span>, <span class="lg-highlight-string">" "</span>, <span class="lg-highlight-string">"world"</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":"{ $concatArrays: [\n [ \"hello\", \" \"],\n [ [ \"world\" ], \"again\"]\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">$concatArrays</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <span class="lg-highlight-string">"hello"</span>, <span class="lg-highlight-string">" "</span>]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"world"</span> ]<!-- -->, <span class="lg-highlight-string">"again"</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[ \"hello\", \" \", [ \"world\" ], \"again\" ]","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-string">"hello"</span>, <span class="lg-highlight-string">" "</span>, <!-- -->[ <span class="lg-highlight-string">"world"</span> ]<!-- -->, <span class="lg-highlight-string">"again"</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>
<p class="leafygreen-ui-1kp3ins">
Create a collection named
<code class="leafygreen-ui-1l06pbn">
warehouses
</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.warehouses.insertMany( [\n { _id : 1, instock: [ \"chocolate\" ], ordered: [ \"butter\", \"apples\" ] },\n { _id : 2, instock: [ \"apples\", \"pudding\", \"pie\" ] },\n { _id : 3, instock: [ \"pears\", \"pecans\" ], ordered: [ \"cherries\" ] },\n { _id : 4, instock: [ \"ice cream\" ], ordered: [ ] }\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">warehouses</span>.<span class="lg-highlight-title lg-highlight-function">insertMany</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->[ <span class="lg-highlight-string">"chocolate"</span> ]<!-- -->, <span class="lg-highlight-attr">ordered</span>: <!-- -->[ <span class="lg-highlight-string">"butter"</span>, <span class="lg-highlight-string">"apples"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->[ <span class="lg-highlight-string">"apples"</span>, <span class="lg-highlight-string">"pudding"</span>, <span class="lg-highlight-string">"pie"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->[ <span class="lg-highlight-string">"pears"</span>, <span class="lg-highlight-string">"pecans"</span> ]<!-- -->, <span class="lg-highlight-attr">ordered</span>: <!-- -->[ <span class="lg-highlight-string">"cherries"</span> ] }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-attr">instock</span>: <!-- -->[ <span class="lg-highlight-string">"ice cream"</span> ]<!-- -->, <span class="lg-highlight-attr">ordered</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 example concatenates the
<code class="leafygreen-ui-1l06pbn">
instock
</code>
and the
<code class="leafygreen-ui-1l06pbn">
ordered
</code>
arrays:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.warehouses.aggregate( [\n { $project: { items: { $concatArrays: [ \"$instock\", \"$ordered\" ] } } }\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">warehouses</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">items</span>: <!-- -->{ <span class="lg-highlight-attr">$concatArrays</span>: <!-- -->[ <span class="lg-highlight-string">"$instock"</span>, <span class="lg-highlight-string">"$ordered"</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id : 1, items : [ \"chocolate\", \"butter\", \"apples\" ] }\n{ _id : 2, items : null }\n{ _id : 3, items : [ \"pears\", \"pecans\", \"cherries\" ] }\n{ _id : 4, items : [ \"ice cream\" ] }","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">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->items <!-- -->: <!-- -->[ <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"butter"</span>, <span class="lg-highlight-string">"apples"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>, <!-- -->items <!-- -->: <span class="lg-highlight-literal">null</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">3</span>, <!-- -->items <!-- -->: <!-- -->[ <span class="lg-highlight-string">"pears"</span>, <span class="lg-highlight-string">"pecans"</span>, <span class="lg-highlight-string">"cherries"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">4</span>, <!-- -->items <!-- -->: <!-- -->[ <span class="lg-highlight-string">"ice cream"</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 also:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/push/#mongodb-group-grp.-push">
<code class="leafygreen-ui-1l06pbn">
$push
</code>
</a>
</p>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/tutorial/update-documents-with-aggregation-pipeline/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Updates with Aggregation Pipeline
<a class="headerlink leafygreen-ui-1kepx47" href="#updates-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="updates-with-aggregation-pipeline">
</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="#create-an-update-aggregation-pipeline-in-atlas" target="_self">
<span>
Create an Update Aggregation Pipeline in Atlas
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#access-the-aggregation-pipeline-builder." target="_self">
<span>
Access the Aggregation Pipeline Builder.
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#create-an-aggregation-pipeline-to-perform-updates." target="_self">
<span>
Create an aggregation pipeline to perform updates.
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#export-the-aggregation-pipeline." target="_self">
<span>
Export the aggregation pipeline.
</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="#updateone-with--set" target="_self">
<span>
updateOne with $set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#updatemany-with--replaceroot-and--set" target="_self">
<span>
updateMany with $replaceRoot and $set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#updatemany-with--set" target="_self">
<span>
updateMany with $set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#updateone-with--set-1" target="_self">
<span>
updateOne with $set
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#updatemany-with--addfields" target="_self">
<span>
updateMany with $addFields
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#update-with-let-variables" target="_self">
<span>
Update with let Variables
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#additional-examples" target="_self">
<span>
Additional Examples
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
To perform update operations, you can use the aggregation pipeline. You can
build and execute aggregation pipelines to perform updates in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas" target="_self">
<span>
MongoDB Atlas
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/" target="_self">
<span>
MongoDB Compass
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self">
<span>
MongoDB Shell
</span>
</a>
, or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/" target="_self">
<span>
Drivers
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
With the update operations, the aggregation pipeline can consist of the
following 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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
<p class="leafygreen-ui-1kp3ins">
Using the aggregation pipeline allows for a more expressive update
statement, such as expressing conditional updates based on current
field values or updating one field using the value of another field(s).
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Create an Update Aggregation Pipeline in Atlas
<a class="headerlink leafygreen-ui-1kepx47" href="#create-an-update-aggregation-pipeline-in-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-an-update-aggregation-pipeline-in-atlas">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
You can use the MongoDB Atlas UI to build an aggregation pipeline to perform
updates. To create and execute aggregation pipelines in the
MongoDB Atlas UI, you must have the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/reference/user-roles/#mongodb-authrole-Project-Data-Access-Read-Only" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
Project Data Access Read Only
</code>
</span>
</a>
role or higher.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Select the database for the collection.The main panel and Namespaces on the left side list the\ncollections in the database.Select the collection.Select the collection on the left-hand side or in the main panel.\nThe main panel displays the Find, Indexes,\nand Aggregation views.Select the Aggregation view.When you first open the Aggregation view, Atlas\ndisplays an empty aggregation pipeline.","name":"Access the Aggregation Pipeline Builder."},{"@type":"HowToStep","text":"Select an aggregation stage.Select an aggregation stage from the Select\ndrop-down menu in the bottom-left panel.The toggle to the right of the drop-down menu dictates whether\nthe stage is enabled.To perform updates with an aggregation, use one of\nthese stages:$addFields$set$project$unset$replaceRoot$replaceWithFill in your aggregation stage.Fill in your stage with the appropriate values.\nIf Comment Mode is enabled, the pipeline\nbuilder provides syntactic guidelines for your selected stage.As you modify your stage, Atlas updates the preview documents on\nthe right based on the results of the current stage.For examples of what you might include in your aggregation stage,\nsee the examples on this page.Add stages as needed. For more information on creating aggregation\npipelines in Atlas, refer to Create an Aggregation Pipeline.","name":"Create an aggregation pipeline to perform updates."},{"@type":"HowToStep","text":"Click Export to Language.You can find this button at the top of the pipeline builder.Select your desired export language.In the Export Pipeline To menu, select your desired\nlanguage.The My Pipeline pane on the left displays your\npipeline in MongoDB Shell syntax. You can copy this directly to execute\nyour pipeline in the MongoDB Shell.The pane on the right displays your pipeline in the selected\nlanguage. Select your preferred language.Select options, if desired.(Optional): Check the Include Import Statements option\nto include the required import statements for the language selected.(Optional): Check the Include Driver Syntax option\nto include Driver-specific code to:Initialize the clientSpecify the database and collectionPerform the aggregation operationCopy the pipeline.Click the Copy button at the top-right of the pipeline\nto copy the pipeline for the selected language to your clipboard.\nPaste the copied pipeline into your application.","name":"Export the aggregation pipeline."}],"name":"Create an Update Aggregation Pipeline in Atlas","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">
Access the Aggregation Pipeline Builder.
<a class="headerlink leafygreen-ui-1kepx47" href="#access-the-aggregation-pipeline-builder." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-the-aggregation-pipeline-builder.">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select the database for the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
The main panel and
<span class="guilabel css-h15tq0">
Namespaces
</span>
on the left side list the
collections in the database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select the collection.
</p>
<p class="leafygreen-ui-1kp3ins">
Select the collection on the left-hand side or in the main panel.
The main panel displays the
<span class="guilabel css-h15tq0">
Find
</span>
,
<span class="guilabel css-h15tq0">
Indexes
</span>
,
and
<span class="guilabel css-h15tq0">
Aggregation
</span>
views.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select the Aggregation view.
</p>
<p class="leafygreen-ui-1kp3ins">
When you first open the
<span class="guilabel css-h15tq0">
Aggregation
</span>
view, Atlas
displays an empty aggregation pipeline.
</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">
Create an aggregation pipeline to perform updates.
<a class="headerlink leafygreen-ui-1kepx47" href="#create-an-aggregation-pipeline-to-perform-updates." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-an-aggregation-pipeline-to-perform-updates.">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select an aggregation stage.
</p>
<p class="leafygreen-ui-1kp3ins">
Select an aggregation stage from the
<span class="guilabel css-h15tq0">
Select
</span>
drop-down menu in the bottom-left panel.
</p>
<p class="leafygreen-ui-1kp3ins">
The toggle to the right of the drop-down menu dictates whether
the stage is enabled.
</p>
<p class="leafygreen-ui-1kp3ins">
To perform updates with an aggregation, use one of
these 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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<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>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Fill in your aggregation stage.
</p>
<p class="leafygreen-ui-1kp3ins">
Fill in your stage with the appropriate values.
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline/#std-label-pipeline-settings" target="_self">
<span>
Comment Mode
</span>
</a>
is enabled, the pipeline
builder provides syntactic guidelines for your selected stage.
</p>
<p class="leafygreen-ui-1kp3ins">
As you modify your stage, Atlas updates the preview documents on
the right based on the results of the current stage.
</p>
<p class="leafygreen-ui-1kp3ins">
For examples of what you might include in your aggregation stage,
see the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-agg-updates-examples" target="_self">
<span>
examples
</span>
</a>
on this page.
</p>
<p class="leafygreen-ui-1kp3ins">
Add stages as needed. For more information on creating aggregation
pipelines in Atlas, refer to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline/#std-label-agg-pipeline-create" target="_self">
<span>
Create an Aggregation Pipeline
<!-- -->
.
</span>
</a>
</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">
Export the aggregation pipeline.
<a class="headerlink leafygreen-ui-1kepx47" href="#export-the-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="export-the-aggregation-pipeline.">
</div>
</a>
</h3>
<ol class="leafygreen-ui-rioki0" type="a">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Click Export to Language.
</p>
<p class="leafygreen-ui-1kp3ins">
You can find this button at the top of the pipeline builder.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select your desired export language.
</p>
<p class="leafygreen-ui-1kp3ins">
In the
<span class="guilabel css-h15tq0">
Export Pipeline To
</span>
menu, select your desired
language.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<span class="guilabel css-h15tq0">
My Pipeline
</span>
pane on the left displays your
pipeline in
<!-- -->
MongoDB Shell
<!-- -->
syntax. You can copy this directly to execute
your pipeline in the
<!-- -->
MongoDB Shell
<!-- -->
.
</p>
<p class="leafygreen-ui-1kp3ins">
The pane on the right displays your pipeline in the selected
language. Select your preferred language.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Select options, if desired.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
(Optional)
</em>
: Check the
<span class="guilabel css-h15tq0">
Include Import Statements
</span>
option
to include the required import statements for the language selected.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
(Optional)
</em>
: Check the
<span class="guilabel css-h15tq0">
Include Driver Syntax
</span>
option
to include Driver-specific code to:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Initialize the client
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Specify the database and collection
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Perform the aggregation operation
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Copy the pipeline.
</p>
<p class="leafygreen-ui-1kp3ins">
Click the
<span class="guilabel css-h15tq0">
Copy
</span>
button at the top-right of the pipeline
to copy the pipeline for the selected language to your clipboard.
Paste the copied pipeline into your application.
</p>
</li>
</ol>
</section>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-agg-updates-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>
<p class="leafygreen-ui-1kp3ins">
The following examples demonstrate how to use the aggregation pipeline
stages
<code class="leafygreen-ui-1l06pbn">
$set
</code>
,
<code class="leafygreen-ui-1l06pbn">
$replaceRoot
</code>
, and
<code class="leafygreen-ui-1l06pbn">
$addFields
</code>
to perform updates.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
updateOne with $set
<a class="headerlink leafygreen-ui-1kepx47" href="#updateone-with--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="updateone-with--set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an example
<code class="leafygreen-ui-1l06pbn">
students
</code>
collection (if the collection does
not currently exist, insert operations will create the 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, test1: 95, test2: 92, test3: 90, modified: new Date(\"01/05/2020\") },\n { _id: 2, test1: 98, test2: 100, test3: 102, modified: new Date(\"01/05/2020\") },\n { _id: 3, test1: 95, test2: 110, modified: new Date(\"01/04/2020\") }\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">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">test1</span>: <span class="lg-highlight-number">95</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">92</span>, <span class="lg-highlight-attr">test3</span>: <span class="lg-highlight-number">90</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"01/05/2020"</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">test1</span>: <span class="lg-highlight-number">98</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-attr">test3</span>: <span class="lg-highlight-number">102</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"01/05/2020"</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">test1</span>: <span class="lg-highlight-number">95</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">110</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"01/04/2020"</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 verify, query the collection:
</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 following
<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>
operation uses an
aggregation pipeline to update the document with
<code class="leafygreen-ui-1l06pbn">
_id: 3
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.updateOne( { _id: 3 }, [ { $set: { \"test3\": 98, modified: \"$$NOW\"} } ] )","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">updateOne</span>( <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span> }<!-- -->, <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"test3"</span>: <span class="lg-highlight-number">98</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-string">"$$NOW"</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">
Specifically, the pipeline consists of a
<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 adds the
<code class="leafygreen-ui-1l06pbn">
test3
</code>
field (and sets its value to
<code class="leafygreen-ui-1l06pbn">
98
</code>
) to the
document and sets the
<code class="leafygreen-ui-1l06pbn">
modified
</code>
field to the current datetime.
The operation uses 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>
for the
current datetime. To access the variable, prefix with
<code class="leafygreen-ui-1l06pbn">
$$
</code>
and enclose
in quotes.
</p>
<p class="leafygreen-ui-1kp3ins">
To verify the update, you can query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.find().pretty()","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>(<!-- -->).<span class="lg-highlight-title lg-highlight-function">pretty</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">
updateMany with $replaceRoot and $set
<a class="headerlink leafygreen-ui-1kepx47" href="#updatemany-with--replaceroot-and--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="updatemany-with--replaceroot-and--set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an example
<code class="leafygreen-ui-1l06pbn">
students2
</code>
collection (if the collection does not
currently exist, insert operations will create the collection):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.insertMany( [\n { \"_id\" : 1, quiz1: 8, test2: 100, quiz2: 9, modified: new Date(\"01/05/2020\") },\n { \"_id\" : 2, quiz2: 5, test1: 80, test2: 89, modified: new Date(\"01/05/2020\") },\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">students2</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-attr">quiz1</span>: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">100</span>, <span class="lg-highlight-attr">quiz2</span>: <span class="lg-highlight-number">9</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"01/05/2020"</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-attr">quiz2</span>: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-attr">test1</span>: <span class="lg-highlight-number">80</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">89</span>, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"01/05/2020"</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 verify, query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.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">students2</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 following
<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>
operation uses an aggregation
pipeline to standardize the fields for the documents (i.e. documents
in the collection should have the same fields) and update the
<code class="leafygreen-ui-1l06pbn">
modified
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.updateMany( {},\n [\n { $replaceRoot: { newRoot:\n { $mergeObjects: [ { quiz1: 0, quiz2: 0, test1: 0, test2: 0 }, \"$$ROOT\" ] }\n } },\n { $set: { modified: \"$$NOW\"} }\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">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">$replaceRoot</span>: <!-- -->{ <span class="lg-highlight-attr">newRoot</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$mergeObjects</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">quiz1</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">quiz2</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">test1</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">test2</span>: <span class="lg-highlight-number">0</span> }<!-- -->, <span class="lg-highlight-string">"$$ROOT"</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">modified</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></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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">
Specifically, the pipeline consists of:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/replaceRoot/#mongodb-pipeline-pipe.-replaceRoot">
<code class="leafygreen-ui-1l06pbn">
$replaceRoot
</code>
</a>
stage with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/mergeObjects/#mongodb-expression-exp.-mergeObjects">
<code class="leafygreen-ui-1l06pbn">
$mergeObjects
</code>
</a>
expression to set default values for
the
<code class="leafygreen-ui-1l06pbn">
quiz1
</code>
,
<code class="leafygreen-ui-1l06pbn">
quiz2
</code>
,
<code class="leafygreen-ui-1l06pbn">
test1
</code>
and
<code class="leafygreen-ui-1l06pbn">
test2
</code>
fields. The
aggregation variable
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-variables/#mongodb-variable-variable.ROOT">
<code class="leafygreen-ui-1l06pbn">
ROOT
</code>
</a>
refers to the current
document being modified. To access the variable, prefix with
<code class="leafygreen-ui-1l06pbn">
$$
</code>
and enclose in quotes. The current document fields will
override the default values.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a
<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 to update the
<code class="leafygreen-ui-1l06pbn">
modified
</code>
field to the
current datetime. The operation uses 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>
for the current datetime. To access the variable,
prefix with
<code class="leafygreen-ui-1l06pbn">
$$
</code>
and enclose in quotes.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To verify the update, you can query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.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">students2</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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
updateMany with $set
<a class="headerlink leafygreen-ui-1kepx47" href="#updatemany-with--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="updatemany-with--set">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an example
<code class="leafygreen-ui-1l06pbn">
students3
</code>
collection (if the collection does not
currently exist, insert operations will create the collection):
</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, \"tests\" : [ 95, 92, 90 ], \"modified\" : ISODate(\"2019-01-01T00:00:00Z\") },\n { \"_id\" : 2, \"tests\" : [ 94, 88, 90 ], \"modified\" : ISODate(\"2019-01-01T00:00:00Z\") },\n { \"_id\" : 3, \"tests\" : [ 70, 75, 82 ], \"modified\" : ISODate(\"2019-01-01T00: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">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>, <span class="lg-highlight-string">"tests"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">95</span>, <span class="lg-highlight-number">92</span>, <span class="lg-highlight-number">90</span> ]<!-- -->, <span class="lg-highlight-string">"modified"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-01T00: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">"tests"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">94</span>, <span class="lg-highlight-number">88</span>, <span class="lg-highlight-number">90</span> ]<!-- -->, <span class="lg-highlight-string">"modified"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-01T00: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">"tests"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">70</span>, <span class="lg-highlight-number">75</span>, <span class="lg-highlight-number">82</span> ]<!-- -->, <span class="lg-highlight-string">"modified"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-01T00: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>
<p class="leafygreen-ui-1kp3ins">
To verify, query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students3.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">students3</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 following
<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>
operation uses an
aggregation pipeline to update the documents with the calculated
grade average and letter grade.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students3.updateMany(\n { },\n [\n { $set: { average : { $trunc: [ { $avg: \"$tests\" }, 0 ] }, modified: \"$$NOW\" } },\n { $set: { grade: { $switch: {\n branches: [\n { case: { $gte: [ \"$average\", 90 ] }, then: \"A\" },\n { case: { $gte: [ \"$average\", 80 ] }, then: \"B\" },\n { case: { $gte: [ \"$average\", 70 ] }, then: \"C\" },\n { case: { $gte: [ \"$average\", 60 ] }, then: \"D\" }\n ],\n default: \"F\"\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">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"> <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <!-- -->average <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$trunc</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$avg</span>: <span class="lg-highlight-string">"$tests"</span> }<!-- -->, <span class="lg-highlight-number">0</span> ] }<!-- -->, <span class="lg-highlight-attr">modified</span>: <span class="lg-highlight-string">"$$NOW"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">grade</span>: <!-- -->{ <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">$gte</span>: <!-- -->[ <span class="lg-highlight-string">"$average"</span>, <span class="lg-highlight-number">90</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"A"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <!-- -->[ <span class="lg-highlight-string">"$average"</span>, <span class="lg-highlight-number">80</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"B"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <!-- -->[ <span class="lg-highlight-string">"$average"</span>, <span class="lg-highlight-number">70</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"C"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">case</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <!-- -->[ <span class="lg-highlight-string">"$average"</span>, <span class="lg-highlight-number">60</span> ] }<!-- -->, <span class="lg-highlight-attr">then</span>: <span class="lg-highlight-string">"D"</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-string">"F"</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">
Specifically, the pipeline consists of:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a
<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 to calculate the truncated average value
of the
<code class="leafygreen-ui-1l06pbn">
tests
</code>
array elements and to update the
<code class="leafygreen-ui-1l06pbn">
modified
</code>
field to the current datetime. To calculate the truncated average,
the stage uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/avg/#mongodb-group-grp.-avg">
<code class="leafygreen-ui-1l06pbn">
$avg
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/trunc/#mongodb-expression-exp.-trunc">
<code class="leafygreen-ui-1l06pbn">
$trunc
</code>
</a>
expressions. The operation uses 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>
for the current datetime. To access the variable,
prefix with
<code class="leafygreen-ui-1l06pbn">
$$
</code>
and enclose in quotes.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a
<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 to add the
<code class="leafygreen-ui-1l06pbn">
grade
</code>
field based on the
<code class="leafygreen-ui-1l06pbn">
average
</code>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/switch/#mongodb-expression-exp.-switch">
<code class="leafygreen-ui-1l06pbn">
$switch
</code>
</a>
expression.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To verify the update, you can query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students3.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">students3</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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
updateOne with $set
<a class="headerlink leafygreen-ui-1kepx47" href="#updateone-with--set-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="updateone-with--set-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an example
<code class="leafygreen-ui-1l06pbn">
students4
</code>
collection (if the collection does
not currently exist, insert operations will create the collection):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students4.insertMany( [\n { \"_id\" : 1, \"quizzes\" : [ 4, 6, 7 ] },\n { \"_id\" : 2, \"quizzes\" : [ 5 ] },\n { \"_id\" : 3, \"quizzes\" : [ 10, 10, 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">students4</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">"quizzes"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">6</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">"quizzes"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">5</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">"quizzes"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">10</span>, <span class="lg-highlight-number">10</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">
To verify, query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students4.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">students4</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 following
<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>
operation uses an
aggregation pipeline to add quiz scores to the document with
<code class="leafygreen-ui-1l06pbn">
_id:
2
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students4.updateOne( { _id: 2 },\n [ { $set: { quizzes: { $concatArrays: [ \"$quizzes\", [ 8, 6 ] ] } } } ]\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">students4</span>.<span class="lg-highlight-title lg-highlight-function">updateOne</span>( <!-- -->{ <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">$set</span>: <!-- -->{ <span class="lg-highlight-attr">quizzes</span>: <!-- -->{ <span class="lg-highlight-attr">$concatArrays</span>: <!-- -->[ <span class="lg-highlight-string">"$quizzes"</span>, <!-- -->[ <span class="lg-highlight-number">8</span>, <span class="lg-highlight-number">6</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 verify the update, query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students4.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">students4</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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
updateMany with $addFields
<a class="headerlink leafygreen-ui-1kepx47" href="#updatemany-with--addfields" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="updatemany-with--addfields">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create an example
<code class="leafygreen-ui-1l06pbn">
temperatures
</code>
collection that contains
temperatures in Celsius (if the collection does not currently exist,
insert operations will create the collection):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.insertMany( [\n { \"_id\" : 1, \"date\" : ISODate(\"2019-06-23\"), \"tempsC\" : [ 4, 12, 17 ] },\n { \"_id\" : 2, \"date\" : ISODate(\"2019-07-07\"), \"tempsC\" : [ 14, 24, 11 ] },\n { \"_id\" : 3, \"date\" : ISODate(\"2019-10-30\"), \"tempsC\" : [ 18, 6, 8 ] }\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">temperatures</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">"date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-06-23"</span>)<!-- -->, <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">4</span>, <span class="lg-highlight-number">12</span>, <span class="lg-highlight-number">17</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">"2019-07-07"</span>)<!-- -->, <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">14</span>, <span class="lg-highlight-number">24</span>, <span class="lg-highlight-number">11</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-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-10-30"</span>)<!-- -->, <span class="lg-highlight-string">"tempsC"</span> <!-- -->: <!-- -->[ <span class="lg-highlight-number">18</span>, <span class="lg-highlight-number">6</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">
To verify, query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.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">temperatures</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 following
<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>
operation uses an
aggregation pipeline to update the documents with the corresponding
temperatures in Fahrenheit:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.updateMany( { },\n [\n { $addFields: { \"tempsF\": {\n $map: {\n input: \"$tempsC\",\n as: \"celsius\",\n in: { $add: [ { $multiply: [\"$$celsius\", 9/5 ] }, 32 ] }\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">temperatures</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">$addFields</span>: <!-- -->{ <span class="lg-highlight-string">"tempsF"</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$map</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">input</span>: <span class="lg-highlight-string">"$tempsC"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">as</span>: <span class="lg-highlight-string">"celsius"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">in</span>: <!-- -->{ <span class="lg-highlight-attr">$add</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$multiply</span>: <!-- -->[<span class="lg-highlight-string">"$$celsius"</span>, <span class="lg-highlight-number">9</span>/<span class="lg-highlight-number">5</span> ] }<!-- -->, <span class="lg-highlight-number">32</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">
Specifically, the pipeline consists of an
<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 to add a new array field
<code class="leafygreen-ui-1l06pbn">
tempsF
</code>
that contains the
temperatures in Fahrenheit. To convert each celsius temperature in
the
<code class="leafygreen-ui-1l06pbn">
tempsC
</code>
array to Fahrenheit, the stage uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/map/#mongodb-expression-exp.-map">
<code class="leafygreen-ui-1l06pbn">
$map
</code>
</a>
expression with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/add/#mongodb-expression-exp.-add">
<code class="leafygreen-ui-1l06pbn">
$add
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/multiply/#mongodb-expression-exp.-multiply">
<code class="leafygreen-ui-1l06pbn">
$multiply
</code>
</a>
expressions.
</p>
<p class="leafygreen-ui-1kp3ins">
To verify the update, you can query the collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.temperatures.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">temperatures</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-updateMany-let-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Update with let Variables
<a class="headerlink leafygreen-ui-1kepx47" href="#update-with-let-variables" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-let-variables">
</div>
</a>
</h3>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
To define variables that you can access elsewhere in the command, use
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#std-label-updateOne-let-syntax">
let
</a>
option.
</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">
To filter results using a variable, you must access the variable
within the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
operator.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
cakeFlavors
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.insertMany( [\n { _id: 1, flavor: \"chocolate\" },\n { _id: 2, flavor: \"strawberry\" },\n { _id: 3, flavor: \"cherry\" }\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">cakeFlavors</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">flavor</span>: <span class="lg-highlight-string">"chocolate"</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">flavor</span>: <span class="lg-highlight-string">"strawberry"</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">flavor</span>: <span class="lg-highlight-string">"cherry"</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
<code class="leafygreen-ui-1l06pbn">
updateOne
</code>
command uses variables set with the
<code class="leafygreen-ui-1l06pbn">
let
</code>
option:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
targetFlavor
</code>
variable is set to
<code class="leafygreen-ui-1l06pbn">
cherry
</code>
. This variable is
used in the
<code class="leafygreen-ui-1l06pbn">
$eq
</code>
expression to specify the match filter.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
newFlavor
</code>
variable is set to
<code class="leafygreen-ui-1l06pbn">
orange
</code>
. This variable is used
in the
<code class="leafygreen-ui-1l06pbn">
$set
</code>
operator to specify the updated
<code class="leafygreen-ui-1l06pbn">
flavor
</code>
value for
the matched document.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.updateOne(\n {\n $expr: { $eq: [ \"$flavor\", \"$$targetFlavor\" ] }\n },\n [\n {\n $set: { flavor: \"$$newFlavor\" }\n }\n ],\n {\n let: { targetFlavor: \"cherry\", newFlavor: \"orange\" }\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">cakeFlavors</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">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$flavor"</span>, <span class="lg-highlight-string">"$$targetFlavor"</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-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"$$newFlavor"</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-attr">let</span>: <!-- -->{ <span class="lg-highlight-attr">targetFlavor</span>: <span class="lg-highlight-string">"cherry"</span>, <span class="lg-highlight-attr">newFlavor</span>: <span class="lg-highlight-string">"orange"</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">
After you run the preceding update operation, the
<code class="leafygreen-ui-1l06pbn">
cakeFlavors
</code>
collection contains these documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n { _id: 1, flavor: 'chocolate' },\n { _id: 2, flavor: 'strawberry' },\n { _id: 3, flavor: 'orange' }\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">flavor</span>: <span class="lg-highlight-string">'chocolate'</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">flavor</span>: <span class="lg-highlight-string">'strawberry'</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">'orange'</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">
Additional Examples
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-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="additional-examples">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
See also the various update method pages for additional examples:
</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/#std-label-updateOne-example-agg">
db.collection.updateOne
</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/#std-label-updateMany-example-agg">
db.collection.updateMany
</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/#std-label-findOneAndUpdate-agg-pipeline">
db.collection.findOneAndUpdate()
</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/#std-label-findAndModify-agg-pipeline">
db.collection.findAndModify()
</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.update/#std-label-example-bulk-find-update-agg">
Bulk.find.update()
</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/#std-label-example-bulk-find-update-one-agg">
Bulk.find.updateOne()
</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.upsert/#std-label-bulk-find-upsert-update-agg-example">
Bulk.find.upsert()
</a>
</p>
</li>
</ul>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/core/databases-and-collections/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Databases and Collections in MongoDB
<a class="headerlink leafygreen-ui-1kepx47" href="#databases-and-collections-in-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="databases-and-collections-in-mongodb">
</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="#databases" target="_self">
<span>
Databases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#collections" target="_self">
<span>
Collections
</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 stores data records as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-document">
documents
</a>
(specifically
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/document/#std-label-bson-document-format">
BSON documents
</a>
) which are
gathered together in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-collection">
collections
</a>
. A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-database">
database
</a>
stores one or more collections of documents.
</p>
<p class="leafygreen-ui-1kp3ins">
You can manage
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/databases/" target="_self">
<span>
databases
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-ui/collections/" target="_self">
<span>
collections
</span>
</a>
on the Atlas cluster from
the Atlas UI,
<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>
, or
<!-- -->
MongoDB Compass
<!-- -->
. This page describes
how to manage databases and collections on the Atlas cluster from the
Atlas UI. For self-managed deployments, you can 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>
or
<!-- -->
MongoDB Compass
<!-- -->
to manage databases and collections.
</p>
<p class="leafygreen-ui-1kp3ins">
Select the client that you want to use to manage databases and
collections.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-5">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_yx232qa2m" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_a7nu8t7sr" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas UI
</div>
</button>
<button aria-controls="_ov3amtdnc" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xa21jkfat" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_4ziooxej4" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_gl3okcl6y" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_gcof8v7dz" class="" id="_5wi1cugtq" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
MongoDB Atlas is a multi-cloud database service that simplifies
deploying and managing your databases on the cloud providers of
your choice.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_1u22ukep4" class="leafygreen-ui-38lglc" id="_rnve7p409" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
The MongoDB Shell,
<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>
, is a JavaScript and Node.js
<span class="leafygreen-ui-vm4wms" tabindex="0">
REPL
</span>
environment for interacting
with MongoDB deployments. To learn more, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self">
<span>
mongosh
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_1lt1zjrf5" class="leafygreen-ui-38lglc" id="_lrlt41g0j" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
MongoDB Compass is a powerful GUI for querying, aggregating, and
analyzing your MongoDB data in a visual environment. To learn
more, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/" target="_self">
<span>
MongoDB Compass
<!-- -->
.
</span>
</a>
</p>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Databases
<a class="headerlink leafygreen-ui-1kepx47" href="#databases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="databases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In MongoDB, databases hold one or more collections of documents.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-11">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_fjs8bg9n2" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_wburzibv2" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas UI
</div>
</button>
<button aria-controls="_79p7dcon4" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hbg9x5cjc" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_q8fp38ktx" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xz9zdwhyz" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_fdli7hqw6" class="" id="_7b2ja5zui" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To select a database to use, log in to Atlas and do the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Navigate to the Collections tab."},{"@type":"HowToStep","text":"Select the database from the list of databases in the left pane."}],"name":"Databases - Atlas UI","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">
Navigate to the
<span class="guilabel css-h15tq0">
Collections
</span>
tab.
<a class="headerlink leafygreen-ui-1kepx47" href="#navigate-to-the-collections-tab." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="navigate-to-the-collections-tab.">
</div>
</a>
</h3>
</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">
Select the database from the list of databases in the left pane.
<a class="headerlink leafygreen-ui-1kepx47" href="#select-the-database-from-the-list-of-databases-in-the-left-pane." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-the-database-from-the-list-of-databases-in-the-left-pane.">
</div>
</a>
</h3>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_aaeg14ut1" class="leafygreen-ui-38lglc" id="_eputn0pwv" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To select a database to use, 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>
, issue the
<code class="leafygreen-ui-1l06pbn">
use <db>
</code>
statement, as in the following example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use myDB","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">use myDB</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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="_g9o4yjtw7" class="leafygreen-ui-38lglc" id="_7dmokdc8i" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To select a database to use, complete the following steps:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"To learn more, see Connect to MongoDB.","name":"Start MongoDB Compass and connect to your cluster."},{"@type":"HowToStep","text":"The Databases tab opens to list the existing databases\nfor your MongoDB deployment.","name":"Select Databases from the left navigation."}],"name":"Databases - MongoDB Compass","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
<!-- -->
MongoDB Compass
<!-- -->
and connect to your cluster.
<a class="headerlink leafygreen-ui-1kepx47" href="#start--and-connect-to-your-cluster." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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--and-connect-to-your-cluster.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/compass/current/connect/" target="_self">
<span>
Connect to MongoDB
<!-- -->
.
</span>
</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">
Select
<span class="guilabel css-h15tq0">
Databases
</span>
from the left navigation.
<a class="headerlink leafygreen-ui-1kepx47" href="#select-databases-from-the-left-navigation." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-databases-from-the-left-navigation.">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<span class="guilabel css-h15tq0">
Databases
</span>
tab opens to list the existing databases
for your MongoDB deployment.
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a Database
<a class="headerlink leafygreen-ui-1kepx47" href="#create-a-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="create-a-database">
</div>
</a>
</h3>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-21">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_syjm74c5w" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_iy22cpu3t" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas UI
</div>
</button>
<button aria-controls="_qlhwmjdnp" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_724qklhdf" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_w66ov9z6y" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_ql51337ms" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_le4cx5x1l" class="" id="_ezzw3wbbi" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To create a new database, log in to Atlas and do the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Navigate to the Collections tab."},{"@type":"HowToStep","text":"Click Create Database."},{"@type":"HowToStep","text":"Enter the database and the collection name to create the\ndatabase and its first collection.","name":"Enter the Database Name and the Collection Name."},{"@type":"HowToStep","text":"Upon successful creation, the database and the collection\ndisplays in the left pane in the Atlas UI.","name":"Click Create."}],"name":"Create a Database - Atlas UI","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">
Navigate to the
<span class="guilabel css-h15tq0">
Collections
</span>
tab.
<a class="headerlink leafygreen-ui-1kepx47" href="#navigate-to-the-collections-tab.-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="navigate-to-the-collections-tab.-1">
</div>
</a>
</h4>
</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">
Click
<span class="guilabel css-h15tq0">
Create Database
</span>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create-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="click-create-database.">
</div>
</a>
</h4>
</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">
Enter the
<span class="guilabel css-h15tq0">
Database Name
</span>
and the
<span class="guilabel css-h15tq0">
Collection Name
</span>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-the-database-name-and-the-collection-name." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enter-the-database-name-and-the-collection-name.">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Enter the database and the collection name to create the
database and its first collection.
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Click
<span class="guilabel css-h15tq0">
Create
</span>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="click-create.">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Upon successful creation, the database and the collection
displays in the left pane in the Atlas UI.
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_rkbja6vxa" class="leafygreen-ui-38lglc" id="_u9u08otis" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
If a database does not exist, MongoDB creates the database when you
first store data for that database. As such, you can switch to a
non-existent database and perform the following operation 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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"use myNewDB\n\ndb.myNewCollection1.insertOne( { x: 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">use myNewDB</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">myNewCollection1</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">x</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
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertOne/#mongodb-method-db.collection.insertOne">
<code class="leafygreen-ui-1l06pbn">
insertOne()
</code>
</a>
operation creates both the
database
<code class="leafygreen-ui-1l06pbn">
myNewDB
</code>
and the collection
<code class="leafygreen-ui-1l06pbn">
myNewCollection1
</code>
if they do
not already exist. Be sure that both the database and collection names
follow MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#std-label-restrictions-on-db-names">
Naming Restrictions
<!-- -->
.
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_fmnj34h1y" class="leafygreen-ui-38lglc" id="_5gyi7ydez" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Open the Databases tab."},{"@type":"HowToStep","text":"Click the Create database button."},{"@type":"HowToStep","text":"Enter database and first collection names in the Create Database dialog."},{"@type":"HowToStep","text":"Click Create Database to create the database and its first collection."}],"name":"Create a Database - MongoDB Compass","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">
Open the
<span class="guilabel css-h15tq0">
Databases
</span>
tab.
<a class="headerlink leafygreen-ui-1kepx47" href="#open-the-databases-tab." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-the-databases-tab.">
</div>
</a>
</h4>
</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">
Click the
<span class="guilabel css-h15tq0">
Create database
</span>
button.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the-create-database-button." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="click-the-create-database-button.">
</div>
</a>
</h4>
</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">
Enter database and first collection names in the
<span class="guilabel css-h15tq0">
Create Database
</span>
dialog.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-database-and-first-collection-names-in-the-create-database-dialog." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enter-database-and-first-collection-names-in-the-create-database-dialog.">
</div>
</a>
</h4>
</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">
Click
<span class="guilabel css-h15tq0">
Create Database
</span>
to create the database and its first collection.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create-database-to-create-the-database-and-its-first-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="click-create-database-to-create-the-database-and-its-first-collection.">
</div>
</a>
</h4>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collections">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Collections
<a class="headerlink leafygreen-ui-1kepx47" href="#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="collections">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB stores documents in collections. Collections are analogous to
tables in relational databases.
</p>
<div class="css-1yvtw5i ej97su30">
<div role="button" tabindex="-1">
<img alt="A collection of MongoDB documents." class="leafygreen-ui-1qnf57e" height="300" src="/docs/manual/images/crud-annotated-collection.bakedsvg.svg" style="--border-color:#C1C7C6" width="600"/>
<div class="css-19pi7x2 ej97su31" style="--color:#444">
click to enlarge
</div>
</div>
</div>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Create a Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#create-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="create-a-collection">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If a collection does not exist, MongoDB creates the collection when you
first store data for that collection.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-32">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_4i8yt9bev" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_qnvo55cy9" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas
</div>
</button>
<button aria-controls="_43zqgtuec" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_dj3p7hy6w" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_9cn1kqabu" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_hea5zfy1r" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_f4qehpag7" class="" id="_0uvok7kh1" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To create a new collection, log in to Atlas and do the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Navigate to the Collections tab."},{"@type":"HowToStep","text":"Click the + icon for the database."},{"@type":"HowToStep","text":"Enter the name of the collection."},{"@type":"HowToStep","text":"Upon successful creation, the collection displays underneath\nthe database in the Atlas UI.","name":"Click Create."}],"name":"Create a Collection - Atlas","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">
Navigate to the
<span class="guilabel css-h15tq0">
Collections
</span>
tab.
<a class="headerlink leafygreen-ui-1kepx47" href="#navigate-to-the-collections-tab.-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="navigate-to-the-collections-tab.-2">
</div>
</a>
</h4>
</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">
Click the
<span class="guilabel css-h15tq0">
+
</span>
icon for the database.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the---icon-for-the-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="click-the---icon-for-the-database.">
</div>
</a>
</h4>
</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">
Enter the name of the collection.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-the-name-of-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="enter-the-name-of-the-collection.">
</div>
</a>
</h4>
</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">
Click
<span class="guilabel css-h15tq0">
Create
</span>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create.-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="click-create.-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Upon successful creation, the collection displays underneath
the database in the Atlas UI.
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_kzaeujh90" class="leafygreen-ui-38lglc" id="_r2zdwowh8" 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":"db.myNewCollection2.insertOne( { x: 1 } )\ndb.myNewCollection3.createIndex( { y: 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">myNewCollection2</span>.<span class="lg-highlight-title lg-highlight-function">insertOne</span>( <!-- -->{ <span class="lg-highlight-attr">x</span>: <span class="lg-highlight-number">1</span> } )</td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">myNewCollection3</span>.<span class="lg-highlight-title lg-highlight-function">createIndex</span>( <!-- -->{ <span class="lg-highlight-attr">y</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">
Both the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.insertOne/#mongodb-method-db.collection.insertOne">
<code class="leafygreen-ui-1l06pbn">
insertOne()
</code>
</a>
and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
createIndex()
</code>
</a>
operations create their
respective collection if they do not already exist. Be sure that the
collection name follows MongoDB
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#std-label-restrictions-on-db-names">
Naming Restrictions
<!-- -->
.
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_jm4wo6c0z" class="leafygreen-ui-38lglc" id="_pqt5161ct" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Click the name of the database where you to want to create a collection in the left navigation."},{"@type":"HowToStep","text":"Click the + icon next to the database name."},{"@type":"HowToStep","text":"Enter the name of the collection in the Create Collection dialog."},{"@type":"HowToStep","text":"Click Create Collection to create the collection."}],"name":"Create a Collection - MongoDB Compass","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">
Click the name of the database where you to want to create a collection in the left navigation.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the-name-of-the-database-where-you-to-want-to-create-a-collection-in-the-left-navigation." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="click-the-name-of-the-database-where-you-to-want-to-create-a-collection-in-the-left-navigation.">
</div>
</a>
</h4>
</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">
Click the
<span class="guilabel css-h15tq0">
+
</span>
icon next to the database name.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the---icon-next-to-the-database-name." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="click-the---icon-next-to-the-database-name.">
</div>
</a>
</h4>
</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">
Enter the name of the collection in the
<span class="guilabel css-h15tq0">
Create Collection
</span>
dialog.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-the-name-of-the-collection-in-the-create-collection-dialog." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enter-the-name-of-the-collection-in-the-create-collection-dialog.">
</div>
</a>
</h4>
</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">
Click
<span class="guilabel css-h15tq0">
Create Collection
</span>
to create the collection.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create-collection-to-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="click-create-collection-to-create-the-collection.">
</div>
</a>
</h4>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Explicit Creation
<a class="headerlink leafygreen-ui-1kepx47" href="#explicit-creation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="explicit-creation">
</div>
</a>
</h3>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-43">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_v0icesf29" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_glur3nwu1" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas
</div>
</button>
<button aria-controls="_pls59cvg7" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_gg1qr7z5r" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_qukyuhofp" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_xsrn697kz" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_5u5m6zyeg" class="" id="_86sxvea1p" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To create a new collection, log in to Atlas and do the following:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Navigate to the Collections tab."},{"@type":"HowToStep","text":"Click the + icon for the database."},{"@type":"HowToStep","text":"Enter the name of the collection."},{"@type":"HowToStep","text":"You can create one of the following types of collections:Capped collectionIf you select to create a capped collection, specify the\nmaximum size in bytes.Time Series CollectionIf you select to create a time series collection, specify\nthe time field and granularity. You can optionally specify\nthe meta field and the time for old data in the collection\nto expire.Clustered Index CollectionIf you select to create a clustered collection, you must\nspecify clustered index key value and a name for the\nclustered index.","name":"Optional. From the Additional Preferences dropdown, select the type of collection that you want to create."},{"@type":"HowToStep","text":"Upon successful creation, the collection displays underneath\nthe database in the Atlas UI.","name":"Click Create."}],"name":"Explicit Creation - Atlas","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">
Navigate to the
<span class="guilabel css-h15tq0">
Collections
</span>
tab.
<a class="headerlink leafygreen-ui-1kepx47" href="#navigate-to-the-collections-tab.-3" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="navigate-to-the-collections-tab.-3">
</div>
</a>
</h4>
</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">
Click the
<span class="guilabel css-h15tq0">
+
</span>
icon for the database.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the---icon-for-the-database.-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="click-the---icon-for-the-database.-1">
</div>
</a>
</h4>
</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">
Enter the name of the collection.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-the-name-of-the-collection.-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="enter-the-name-of-the-collection.-1">
</div>
</a>
</h4>
</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">
Optional. From the
<span class="guilabel css-h15tq0">
Additional Preferences
</span>
dropdown, select the type of collection that you want to create.
<a class="headerlink leafygreen-ui-1kepx47" href="#optional.-from-the-additional-preferences-dropdown--select-the-type-of-collection-that-you-want-to-create." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="optional.-from-the-additional-preferences-dropdown--select-the-type-of-collection-that-you-want-to-create.">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can create one of the following types of collections:
</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/capped-collections/#std-label-manual-capped-collection">
Capped collection
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you select to create a capped collection, specify the
maximum size in bytes.
</p>
</li>
<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-landing">
Time Series Collection
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you select to create a time series collection, specify
the time field and granularity. You can optionally specify
the meta field and the time for old data in the collection
to expire.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/clustered-collections/#std-label-clustered-collections">
Clustered Index Collection
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If you select to create a clustered collection, you must
specify clustered index key value and a name for the
clustered index.
</p>
</li>
</ul>
</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Click
<span class="guilabel css-h15tq0">
Create
</span>
.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create.-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="click-create.-2">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Upon successful creation, the collection displays underneath
the database in the Atlas UI.
</p>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div aria-labelledby="_10hbzpwgc" class="leafygreen-ui-38lglc" id="_06p35bhgg" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
MongoDB provides the
<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>
method to
explicitly create a collection with various options, such as setting
the maximum size or the documentation validation rules. If you are not
specifying these options, you do not need to explicitly create the
collection since MongoDB creates new collections when you first store
data for the collections.
</p>
<p class="leafygreen-ui-1kp3ins">
To modify these collection options, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collMod/#mongodb-dbcommand-dbcmd.collMod">
<code class="leafygreen-ui-1l06pbn">
collMod
</code>
.
</a>
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_813zmbi2u" class="leafygreen-ui-38lglc" id="_wqfbi4han" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Click the name of the database where you to want to create a collection in the left navigation."},{"@type":"HowToStep","text":"Click the Create collection button."},{"@type":"HowToStep","text":"Enter the name of the collection and optionally, configure additional preferences."},{"@type":"HowToStep","text":"MongoDB Compass provides the following additional preferences that\nyou can configure for your collection:Create a Capped CollectionCreate a Clustered CollectionCreate a Collection with CollationCreate a Collection with Encrypted FieldCreate a Time Series Collection","name":"Click Create Collection to create the collection."}],"name":"Explicit Creation - MongoDB Compass","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">
Click the name of the database where you to want to create a collection in the left navigation.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the-name-of-the-database-where-you-to-want-to-create-a-collection-in-the-left-navigation.-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="click-the-name-of-the-database-where-you-to-want-to-create-a-collection-in-the-left-navigation.-1">
</div>
</a>
</h4>
</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">
Click the
<span class="guilabel css-h15tq0">
Create collection
</span>
button.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-the-create-collection-button." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="click-the-create-collection-button.">
</div>
</a>
</h4>
</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">
Enter the name of the collection and optionally, configure additional preferences.
<a class="headerlink leafygreen-ui-1kepx47" href="#enter-the-name-of-the-collection-and-optionally--configure-additional-preferences." title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="enter-the-name-of-the-collection-and-optionally--configure-additional-preferences.">
</div>
</a>
</h4>
</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">
Click
<span class="guilabel css-h15tq0">
Create Collection
</span>
to create the collection.
<a class="headerlink leafygreen-ui-1kepx47" href="#click-create-collection-to-create-the-collection.-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="click-create-collection-to-create-the-collection.-1">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
MongoDB Compass
<!-- -->
provides the following additional preferences that
you can configure for your collection:
</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/compass/current/collections/capped-collection/" target="_self">
<span>
Create a Capped Collection
</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/collections/clustered-collection/" target="_self">
<span>
Create a Clustered Collection
</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/collections/collation-collection/" target="_self">
<span>
Create a Collection with Collation
</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/collections/encrypted-collection/" target="_self">
<span>
Create a Collection with Encrypted Field
</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/collections/time-series-collection/" target="_self">
<span>
Create a Time Series Collection
</span>
</a>
</p>
</li>
</ul>
</section>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Document Validation
<a class="headerlink leafygreen-ui-1kepx47" href="#document-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="document-validation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By default, a collection does not require its documents to have the
same schema; i.e. the documents in a single collection do not need to
have the same set of fields and the data type for a field can differ
across documents within a collection.
</p>
<p class="leafygreen-ui-1kp3ins">
However, you can enforce
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/">
document validation rules
</a>
for a collection during update and insert operations.
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/">
Schema Validation
</a>
for details.
</p>
<p class="leafygreen-ui-1kp3ins">
For deployments hosted in MongoDB Atlas, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/performance-advisor/" target="_self">
<span>
Performance Advisor
</span>
</a>
and the MongoDB Atlas UI detect common schema
design issues and suggest modifications that follow MongoDB best
practices. To learn more, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/performance-advisor/schema-suggestions/#schema-suggestions" target="_self">
<span>
Schema Suggestions
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Modifying Document Structure
<a class="headerlink leafygreen-ui-1kepx47" href="#modifying-document-structure" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="modifying-document-structure">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To change the structure of the documents in a collection, such as add
new fields, remove existing fields, or change the field values to a new
type, update the documents to the new structure.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-collections-uuids">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unique Identifiers
<a class="headerlink leafygreen-ui-1kepx47" href="#unique-identifiers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unique-identifiers">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Collections are assigned an immutable
<span class="leafygreen-ui-vm4wms" tabindex="0">
UUID
</span>
. The
collection UUID remains the same across all members of a replica set
and shards in a sharded cluster.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-f2qztv" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-47">
<div aria-label="Tabs to describe usage of atlas/compass/mongosh" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_zdqsa66ts" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_tp6tpky44" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Atlas
</div>
</button>
<button aria-controls="_qmgwokybn" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_aqhznfux8" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongosh
</div>
</button>
<button aria-controls="_101yr4hd6" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_0t3pntqu9" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
MongoDB Compass
</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="_p3h16es1l" class="" id="_dczui3y1m" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
</div>
</div>
</div>
<div>
<div aria-labelledby="_vwxd06jf1" class="leafygreen-ui-38lglc" id="_ykkj5sgkb" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
<p class="leafygreen-ui-1kp3ins">
To retrieve the UUID for a collection, run either the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/manual/reference/command/listCollections/" target="_self">
<span>
listCollections
</span>
</a>
command
or the
<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>
method.
</p>
</div>
</div>
</div>
<div>
<div aria-labelledby="_1nfy5sfl0" class="leafygreen-ui-38lglc" id="_uw7ftz3up" role="tabpanel">
<div class="leafygreen-ui-1kdmo88">
</div>
</div>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/queryStats/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$queryStats (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-querystats--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="-querystats--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="#requirements" target="_self">
<span>
Requirements
</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="#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-x9koo9" href="#how--querystats-tracks-query-statistics" target="_self">
<span>
How $queryStats Tracks Query Statistics
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#how--querystats-groups-returned-documents" target="_self">
<span>
How $queryStats Groups Returned Documents
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#how--querystats-transforms-data-using-transformidentifiers" target="_self">
<span>
How $queryStats Transforms Data Using transformIdentifiers
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#-querystats-log-entries" target="_self">
<span>
$queryStats Log Entries
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#change-streams" target="_self">
<span>
Change Streams
</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-x9koo9" href="#collection-type" target="_self">
<span>
Collection Type
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#query-shape" target="_self">
<span>
Query Shape
</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="#untransformed-example" target="_self">
<span>
Untransformed Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#transformed-example" target="_self">
<span>
Transformed Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#mongodb-atlas-data-collection" target="_self">
<span>
MongoDB Atlas Data Collection
</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">
$queryStats
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-pipeline-pipe.-queryStats" 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.-queryStats">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
<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
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
aggregation stage is unsupported and is not
guaranteed to be stable in a future release. Don't build
functionality that relies on a specific output format of this stage,
since the output may change in a future release.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns runtime statistics for recorded queries.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
collects and reports metrics for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.aggregate/#mongodb-method-db.collection.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate()
</code>
</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>
,
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.distinct/#mongodb-method-db.collection.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct()
</code>
</a>
queries.
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
does
not collect information for queries that use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/queryable-encryption/#std-label-qe-manual-feature-qe">
Queryable Encryption
<!-- -->
.
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Requirements
<a class="headerlink leafygreen-ui-1kepx47" href="#requirements" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="requirements">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
stage is enabled on deployments hosted on
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/" target="_self">
<span>
MongoDB Atlas
</span>
</a>
with a cluster tier of at least M10.
</p>
<p class="leafygreen-ui-1kp3ins">
To run the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
stage, your pipeline must meet the following
requirements:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The pipeline must be run on the
<code class="leafygreen-ui-1l06pbn">
admin
</code>
database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
must be the first stage in the pipeline.
</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>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( {\n aggregate: 1,\n pipeline: [\n {\n $queryStats: {\n transformIdentifiers: {\n algorithm: <string>,\n hmacKey: <bindata> /* subtype 8 - used for sensitive data */\n }\n }\n }\n ],\n cursor: { }\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"> <span class="lg-highlight-attr">aggregate</span>: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$queryStats</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transformIdentifiers</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <<!-- -->string<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hmacKey</span>: <<!-- -->binData<!-- -->> <span class="lg-highlight-comment">/* subtype 8 -</span><span class="lg-highlight-comment"> used for sensitive </span><span class="lg-highlight-comment">data */</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">cursor</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>
<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 run
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
on a specific collection. For complete
examples, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-examples" target="_self">
<span>
Examples
<!-- -->
.
</span>
</a>
</p>
</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">
$queryStats
</code>
takes 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: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>
Field
</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>
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">
transformIdentifiers
</code>
</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>
Document
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies additional transformation options for the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
output.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.algorithm
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Required if specifying the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
object
</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 type of hash transformation applied to namespace information
and field names in output. The only currently supported
<code class="leafygreen-ui-1l06pbn">
algorithm
</code>
value is
<code class="leafygreen-ui-1l06pbn">
hmac-sha-256
</code>
.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.hmacKey
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Required if specifying the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
object
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
binData
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The private key input in the HMAC transformation.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</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">
If your deployment enforces access control, the user running
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
must have the following permissions:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To run
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
without the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
option,
the user must have the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-queryStatsRead">
<code class="leafygreen-ui-1l06pbn">
queryStatsRead
</code>
</a>
privilege action.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To run
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
with the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
option, the
user must have the both the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-queryStatsRead">
<code class="leafygreen-ui-1l06pbn">
queryStatsRead
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-queryStatsReadTransformed">
<code class="leafygreen-ui-1l06pbn">
queryStatsReadTransformed
</code>
</a>
privilege actions.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The built-in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-clusterMonitor">
<code class="leafygreen-ui-1l06pbn">
clusterMonitor
</code>
</a>
role provides the
<code class="leafygreen-ui-1l06pbn">
queryStatsRead
</code>
and
<code class="leafygreen-ui-1l06pbn">
queryStatsReadTransformed
</code>
privileges. The
following example grants the
<code class="leafygreen-ui-1l06pbn">
clusterMonitor
</code>
role 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":"db.grantRolesToUser(\n \"<user>\",\n [ { role: \"clusterMonitor\", db: \"admin\" } ]\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">grantRolesToUser</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"<user>"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">role</span>: <span class="lg-highlight-string">"clusterMonitor"</span>, <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">"admin"</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>
<p class="leafygreen-ui-1kp3ins">
The following sections describe behavioral details of the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
stage.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
How $queryStats Tracks Query Statistics
<a class="headerlink leafygreen-ui-1kepx47" href="#how--querystats-tracks-query-statistics" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="how--querystats-tracks-query-statistics">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Statistics for the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
stage are tracked in a virtual
collection that is stored in-memory. The memory limit for the virtual
collection is 1% of the system's total memory.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
How $queryStats Groups Returned Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#how--querystats-groups-returned-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="how--querystats-groups-returned-documents">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
groups queries with common properties into the same
output document. The resulting document is called a
<strong>
query stats
entry
</strong>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
groups similar queries together by normalizing
user-provided field values to their data types. For example, a filter
specified as
<code class="leafygreen-ui-1l06pbn">
{ item: 'card' }
</code>
is normalized to
<code class="leafygreen-ui-1l06pbn">
{ item :
'?string'}
</code>
.
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
also normalizes the values of some query
options like
<code class="leafygreen-ui-1l06pbn">
hint
</code>
and
<code class="leafygreen-ui-1l06pbn">
comment
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
preserves literal values for options like
<code class="leafygreen-ui-1l06pbn">
readConcern
</code>
and
<code class="leafygreen-ui-1l06pbn">
readPreference
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For the complete list of options included in a query stats entry, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-find-query-shape" target="_self">
<span>
find Command Query Shape
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
How $queryStats Transforms Data Using transformIdentifiers
<a class="headerlink leafygreen-ui-1kepx47" href="#how--querystats-transforms-data-using-transformidentifiers" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="how--querystats-transforms-data-using-transformidentifiers">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When an HMAC key is specified to the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
option,
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
uses the HMAC key to apply an HMAC-SHA-256 hash function
on the following data:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Document field names
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Collection names
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Database names
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
<strong>
does not
</strong>
apply the HMAC transformation to the
following data:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MQL keywords such as operator names (for example,
<code class="leafygreen-ui-1l06pbn">
$gte
</code>
).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Parameter names such as the
<code class="leafygreen-ui-1l06pbn">
partitionBy
</code>
parameter in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Field values.
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
normalizes field values in a query to
their data types (such as number or string) when the query is
recorded.
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
never stores field values that contain user
data.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For an example of transformed output, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-example-transformed" target="_self">
<span>
Transformed Example
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
$queryStats Log Entries
<a class="headerlink leafygreen-ui-1kepx47" href="#-querystats-log-entries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="-querystats-log-entries">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
MongoDB records
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
operations in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/mongodb-logs/" target="_self">
<span>
deployment logs
</span>
</a>
. By default, MongoDB only logs the invocation of
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
operations, not the operation's output. For
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
operations that include the
<code class="leafygreen-ui-1l06pbn">
transformIdentifiers
</code>
option, you can specify whether the transformed output is included in
the log entry.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn how to control
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
logging behavior, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/queryStats/toggle-logging/#std-label-queryStats-toggle-logging">
Toggle $queryStats Log Output
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-change-stream-behavior">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Change Streams
<a class="headerlink leafygreen-ui-1kepx47" href="#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="change-streams">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Query stats for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change streams
</a>
are updated when
one of these events occur:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A cursor is created
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore">
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
</a>
operation completes
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A cursor closes
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Query stats reported for change streams have these behaviors:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Execution metrics such as
<code class="leafygreen-ui-1l06pbn">
totalExecMicros
</code>
contain information for
the most recent operation (cursor creation,
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
, or cursor close).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Internal
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
operations increment the
<code class="leafygreen-ui-1l06pbn">
execCount
</code>
metric.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
firstResponseExecMicros
</code>
and
<code class="leafygreen-ui-1l06pbn">
totalExecMicros
</code>
are always the
same because stats are collected and updated for each
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
operation.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
When the cursor closes,
<code class="leafygreen-ui-1l06pbn">
lastExecutionMicros
</code>
is 0.
</p>
</li>
</ul>
</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">
$queryStats
</code>
returns an array of query stats entries. Some query
stats entry properties contain literal values, and some properties are
normalized to group common queries.
</p>
<p class="leafygreen-ui-1kp3ins">
Query stats entries contain the following top-level documents:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<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>
Document
</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">
key
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The unique combination of attributes that define an entry in the
query stats output. The
<code class="leafygreen-ui-1l06pbn">
key
</code>
contains attributes such as:
</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/query-shapes/#std-label-query-shapes">
Query shape
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Client information
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Read concern
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-collectionType" target="_self">
<span>
Collection type
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Each unique combination of attributes creates a separate
entry in the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
virtual collection.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
asOf
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The UTC time when
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
read this entry from the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
virtual collection.
<code class="leafygreen-ui-1l06pbn">
asOf
</code>
does not necessarily
return the same UTC time for each result. Internally, the data
structure is partitioned, and each partition will be read at an
individual point in time.
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
metrics
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains aggregated runtime metrics associated with each query
stats entry. Each query stats entry records statistics for each
query that shares the same key.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
Each document in the output array contains the following fields:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<col style="width:25%"/>
<col style="width:10%"/>
<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
</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>
Literal or Normalized
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the query shape and additional query attributes that
group a set of queries together
</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.queryShape
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains attributes used to group similar queries together. For
more information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-queryShape" target="_self">
<span>
Query Shape
<!-- -->
.
</span>
</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">
key.client
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes client information associated with the key
</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.client.application
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The client application name
</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.client.driver
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes the driver used to issue the query
</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.client.driver.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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Name of the driver used to issue the query. Possible values
include
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
and
<code class="leafygreen-ui-1l06pbn">
nodejs
</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.client.driver.version
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Version number of the driver used to issue the query
</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.client.os
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes the operating system used by the client that issued the
query
</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.client.os.type
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Type of the operating system
</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.client.os.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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Name of the operating system
</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.client.os.architecture
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Architecture of the operating system. Possible values include
<code class="leafygreen-ui-1l06pbn">
arm64
</code>
and
<code class="leafygreen-ui-1l06pbn">
x86_64
</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.client.os.version
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Version number of the operating system
</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.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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/read-concern/#std-label-read-concern">
read concern
</a>
for the key
</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.collectionType
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The type of collection the query was issued on. For more
information, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-queryStats-collectionType" target="_self">
<span>
Collection Type
<!-- -->
.
</span>
</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">
key.hint
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Document or String
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Normalized
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The index that was used as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.hint/#std-label-cursor-hint">
hint
</a>
for the
query
</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.batchSize
</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>
Normalized
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.batchSize/#std-label-cursor-batchSize">
batch size
</a>
for the key. Batch size
specifies the number of documents to return in each batch of the
response from the MongoDB instance.
</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.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>
Normalized
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Comment associated with the key
</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.maxTimeMS
</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>
Normalized
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.maxTimeMS/#std-label-cursor-maxTimeMS">
maxTimeMS
</a>
value associated with the key
</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.noCursorTimeout
</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>
Normalized
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.noCursorTimeout/#std-label-cursor-noCursorTimeout">
noCursorTimeout
</a>
option
associated with the key
</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.allowPartialResults
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.allowPartialResults/#std-label-cursor-allowPartialResults">
allowPartialResults
</a>
option
associated with the key
</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.readPreference
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference/#std-label-read-preference">
Read preference
</a>
associated with the key
</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.apiVersion
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The Stable API version associated with the key. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api">
Stable API
<!-- -->
.
</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">
key.apiStrict
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<code class="leafygreen-ui-1l06pbn">
apiStrict
</code>
parameter value associated with the key. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api-params">
Stable API Parameters
<!-- -->
.
</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">
key.apiDeprecationErrors
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<code class="leafygreen-ui-1l06pbn">
apiDeprecationErrors
</code>
parameter value associated with the
key. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-stable-api-params">
Stable API Parameters
<!-- -->
.
</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">
keyHash
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
A hashed representation of the values in the
<code class="leafygreen-ui-1l06pbn">
key
</code>
. Each unique
<code class="leafygreen-ui-1l06pbn">
keyHash
</code>
value corresponds to a unique entry in the
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
memory store.
</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">
metrics
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes runtime statistics for the key
</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">
metrics.lastExecutionMicros
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Execution runtime for the most recent query for all queries with
the given key
</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">
metrics.execCount
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Number of times that queries with the given key have been
executed
</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">
metrics.keysExamined
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes the number of keys examined by queries
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.keysExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sum
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Total number of keys examined
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.keysExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.max
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Maximum number of keys examined
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.keysExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.min
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Fewest number of keys examined
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.keysExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sumOfSquares
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberDecimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Sum of squares of number of keys examined.
</p>
<p class="leafygreen-ui-1kp3ins">
A high
<code class="leafygreen-ui-1l06pbn">
sumOfSquares
</code>
value indicates high variance in the
number of keys examined in individual queries.
</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">
metrics.docsExamined
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes the number of documents examined by queries
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sum
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Total number of documents examined in the query
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.max
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Maximum number of documents examined
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.min
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Minimum number of documents examined
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsExamined
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sumOfSquares
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberDecimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Sum of squares of number of documents examined.
</p>
<p class="leafygreen-ui-1kp3ins">
A high
<code class="leafygreen-ui-1l06pbn">
sumOfSquares
</code>
value indicates high variance in the
number of documents examined in individual queries.
</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">
metrics.hasSortStage
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
when MongoDB must sort the documents after it receives
the documents from a cursor.
</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">
metrics.usedDisk
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
when the query writes data to temporary files due to
memory restrictions.
</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">
metrics.fromMultiPlanner
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
when the query planner evaluates multiple plans before
choosing the winning execution plan for the query.
</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">
metrics.fromPlanCache
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
true
</code>
when the query planner is able to use a plan from the
plan cache.
</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">
metrics.totalExecMicros
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Describes the total time spent running queries with the given
key. If the query resulted in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/getMore/#mongodb-dbcommand-dbcmd.getMore">
<code class="leafygreen-ui-1l06pbn">
getMores
</code>
</a>
,
<code class="leafygreen-ui-1l06pbn">
totalExecMicros
</code>
includes the time spent processing the
<code class="leafygreen-ui-1l06pbn">
getMore
</code>
requests.
<code class="leafygreen-ui-1l06pbn">
totalExecMicros
</code>
does not include time
spent waiting for the client.
</p>
<p class="leafygreen-ui-1kp3ins">
All subfields of
<code class="leafygreen-ui-1l06pbn">
totalExecMicros
</code>
are reported in
microseconds.
</p>
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.totalExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sum
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Total time spent running queries with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.totalExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.max
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Longest amount of time spent running a query with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.totalExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.min
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Shortest amount of time spent running a query with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.totalExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sumOfSquares
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberDecimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Sum of squares of the total execution times for all queries
with the given key. A high
<code class="leafygreen-ui-1l06pbn">
sumOfSquares
</code>
value indicates
high variance in query execution times.
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.firstResponseExecMicros
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Describes the time spent from when a query within the key began
processing to when the server returns the first batch of results
</p>
<p class="leafygreen-ui-1kp3ins">
All subfields of
<code class="leafygreen-ui-1l06pbn">
firstResponseExecMicros
</code>
are reported in
microseconds.
</p>
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.firstResponseExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sum
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Combined amount of time spent from the beginning of query
processing to when the server returns the first batch of results
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.firstResponseExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.max
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Longest amount of time spent from the beginning of query
processing to when the server returns the first batch of results
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.firstResponseExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.min
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Shortest amount of time spent from the beginning of query
processing to when the server returns the first batch of results
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.firstResponseExecMicros
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sumOfSquares
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberDecimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Sum of squares of amounts of time spent from the beginning of
query processing to when the server returns the first batch of
results.
</p>
<p class="leafygreen-ui-1kp3ins">
A high
<code class="leafygreen-ui-1l06pbn">
sumOfSquares
</code>
value indicates high variance in
query processing times.
</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">
metrics.docsReturned
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Describes the number of documents returned by queries within the
key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsReturned
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sum
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Total number of documents returned by queries with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsReturned
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.max
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Maximum number of documents returned by a query with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsReturned
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.min
</code>
</div>
</div>
</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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Fewest number of documents returned by a query with the given key
</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">
metrics
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.docsReturned
</code>
</div>
<div class="line">
<code class="leafygreen-ui-1l06pbn">
.sumOfSquares
</code>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
NumberDecimal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Sum of squares of number of documents returned by a query within
the key.
</p>
<p class="leafygreen-ui-1kp3ins">
A high
<code class="leafygreen-ui-1l06pbn">
sumOfSquares
</code>
value indicates high variance in the
number of documents returned between individual queries.
</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">
metrics.firstSeenTimestamp
</code>
</div>
</div>
</td>
<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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Time that a query with the given key was first used since the last
restart
</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">
metrics.lastSeenTimestamp
</code>
</div>
</div>
</td>
<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>
Literal
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Time that a query with the given key was most recently used
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-collectionType">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Collection Type
<a class="headerlink leafygreen-ui-1kepx47" href="#collection-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="collection-type">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
key.collectionType
</code>
field indicates the type of collection that
the recorded query was issued on. The
<code class="leafygreen-ui-1l06pbn">
collectionType
</code>
can be one of
the following values:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:10%"/>
<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>
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">
changeStream
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The query was a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change stream operation
<!-- -->
.
</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">
collection
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The query was issued on a standard
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/databases-and-collections/#std-label-collections">
collection
<!-- -->
.
</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">
nonExistent
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The query was issued on a collection that does not exist.
</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">
timeseries
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The query was issued on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries-collections/#std-label-manual-timeseries-collection">
timeseries collection
<!-- -->
.
</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">
view
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The query was issued on a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
view
<!-- -->
.
</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">
virtual
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
The query was issued on a virtual collection. The following
operations occur in virtual collections:
</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/currentOp/#mongodb-pipeline-pipe.-currentOp">
<code class="leafygreen-ui-1l06pbn">
$currentOp
</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/documents/#mongodb-pipeline-pipe.-documents">
<code class="leafygreen-ui-1l06pbn">
$documents
</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/listLocalSessions/#mongodb-pipeline-pipe.-listLocalSessions">
<code class="leafygreen-ui-1l06pbn">
$listLocalSessions
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-pipeline-pipe.-queryStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
</span>
</a>
</p>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-queryShape">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Query Shape
<a class="headerlink leafygreen-ui-1kepx47" href="#query-shape" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-shape">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
key.queryShape
</code>
document contains query shape fields. To learn
about query shapes, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/query-shapes/#std-label-query-shapes">
Query Shapes
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The fields in
<code class="leafygreen-ui-1l06pbn">
key.queryShape
</code>
vary based on the
command that resulted in the query stats entry.
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
creates
query stats entries for
<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/command/find/#mongodb-dbcommand-dbcmd.find">
<code class="leafygreen-ui-1l06pbn">
find
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/distinct/#mongodb-dbcommand-dbcmd.distinct">
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
</a>
commands.
</p>
<p class="leafygreen-ui-1kp3ins">
Each query shape property corresponds to a query option. For example,
<code class="leafygreen-ui-1l06pbn">
key.queryShape.sort
</code>
corresponds to 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>
specification for the query shape.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-find-query-shape">
</span>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
find Command Query Shape
<a class="headerlink leafygreen-ui-1kepx47" href="#find-command-query-shape" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-command-query-shape">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The following table describes the query shape properties for
<code class="leafygreen-ui-1l06pbn">
find
</code>
commands.
</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%"/>
</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>
Literal or Normalized
</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.queryShape.filter
</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>
Normalized
</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.queryShape.sort
</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>
Literal
</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.queryShape.projection
</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>
Normalized
</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.queryShape.skip
</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>
Normalized
</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.queryShape.limit
</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>
Normalized
</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.queryShape.singleBatch
</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>
Literal
</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.queryShape.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>
Normalized
</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.queryShape.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>
Normalized
</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.queryShape.returnKey
</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>
Literal
</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.queryShape.showRecordId
</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>
Literal
</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.queryShape.tailable
</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>
Literal
</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.queryShape.oplogReplay
</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>
Literal
</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.queryShape.awaitData
</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>
Literal
</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.queryShape.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>
Literal
</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.queryShape.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>
Literal
</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.queryShape.let
</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>
Normalized
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-aggregate-query-shape">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
aggregate Command Query Shape
<a class="headerlink leafygreen-ui-1kepx47" href="#aggregate-command-query-shape" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="aggregate-command-query-shape">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The following table describes the query shape properties for
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
commands.
</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%"/>
</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>
Literal or Normalized
</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.queryShape.pipeline
</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>
Normalized
</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.queryShape.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>
Literal
</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.queryShape.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>
Literal
</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.queryShape.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>
Literal
</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.queryShape.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>
Normalized
</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.queryShape.let
</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>
Normalized
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-distinct-query-shape">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
distinct Command Query Shape
<a class="headerlink leafygreen-ui-1kepx47" href="#distinct-command-query-shape" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="distinct-command-query-shape">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The following table describes the query shape properties for
<code class="leafygreen-ui-1l06pbn">
distinct
</code>
commands.
</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%"/>
</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>
Literal or Normalized
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
key.queryShape.key
</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>
Literal
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
key.queryShape.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>
Normalized
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
key.queryShape.query
</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>
Normalized
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-examples">
</span>
</section>
</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">
To run the examples in this section, start with the following data:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products.insertMany(\n [\n { item: \"card\", qty: 15 },\n { item: \"envelope\", qty: 20 },\n { item: \"stamps\" , qty: 30 }\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">products</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">item</span>: <span class="lg-highlight-string">"card"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">15</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"envelope"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">20</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"stamps"</span> <!-- -->, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">30</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">
Then, run these commands:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.products.find( { item: \"card\" } )\n\ndb.products.aggregate( [\n {\n $match: { qty: { $gt: 20 } }\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">products</span>.<span class="lg-highlight-title lg-highlight-function">find</span>( <!-- -->{ <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"card"</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-property">products</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">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">20</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 examples show the output of
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
using
different types of data transformation:
</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-queryStats-example-untransformed" target="_self">
<span>
Untransformed Example
</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-queryStats-example-transformed" target="_self">
<span>
Transformed Example
</span>
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-example-untransformed">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Untransformed Example
<a class="headerlink leafygreen-ui-1kepx47" href="#untransformed-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="untransformed-example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Input:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n {\n $queryStats: { }\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">"admin"</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">$queryStats</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">
Output:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"[\n {\n key: {\n queryShape: {\n cmdNs: { db: 'test', coll: 'products' },\n command: 'find',\n filter: { item: { '$eq': '?string' } }\n },\n client: {\n driver: { name: 'nodejs|mongosh', version: '5.1.0' },\n os: {\n type: 'Darwin',\n name: 'darwin',\n architecture: 'arm64',\n version: '22.6.0'\n },\n platform: 'Node.js v16.19.1, LE (unified)',\n version: '5.1.0|1.8.0',\n application: { name: 'mongosh 1.8.0' }\n },\n collectionType: 'collection'\n },\n keyHash: 'dsoJ+LHAru0z6MJ1/IygJnnLTrlpVYYmPnlmNZbZrLI=',\n metrics: {\n lastExecutionMicros: Long(\"4254\"),\n execCount: Long(\"1\"),\n totalExecMicros: {\n sum: Long(\"4254\"),\n max: Long(\"4254\"),\n min: Long(\"4254\"),\n sumOfSquares: Decimal128(\"18096516\")\n },\n firstResponseExecMicros: {\n sum: Long(\"4254\"),\n max: Long(\"4254\"),\n min: Long(\"4254\"),\n sumOfSquares: Decimal128(\"18096516\")\n },\n docsReturned: {\n sum: Long(\"1\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"1\")\n },\n firstSeenTimestamp: ISODate(\"2023-09-14T12:30:27.989Z\"),\n latestSeenTimestamp: ISODate(\"2023-09-14T12:30:27.989Z\")\n },\n asOf: Timestamp({ t: 1694695007, i: 0 })\n },\n {\n key: {\n queryShape: {\n cmdNs: { db: 'test', coll: 'products' },\n command: 'aggregate',\n pipeline: [\n { '$match': { qty: { '$gt': '?number' } } }\n ]\n },\n apiVersion: '1',\n client: {\n driver: { name: 'nodejs|mongosh', version: '5.1.0' },\n os: {\n type: 'Darwin',\n name: 'darwin',\n architecture: 'arm64',\n version: '22.6.0'\n },\n platform: 'Node.js v16.19.1, LE (unified)',\n version: '5.1.0|1.8.0',\n application: { name: 'mongosh 1.8.0' }\n },\n collectionType: 'collection',\n cursor: { batchSize: '?number' }\n },\n keyHash: '2QLBfL0m1lliStdN4XvBjqVBtZQ6ffaB2L1pJ99twT8=',\n metrics: {\n lastExecutionMicros: Long(\"350\"),\n execCount: Long(\"3\"),\n totalExecMicros: {\n sum: Long(\"3084\"),\n max: Long(\"2499\"),\n min: Long(\"235\"),\n sumOfSquares: Decimal128(\"6422726\")\n },\n firstResponseExecMicros: {\n sum: Long(\"3084\"),\n max: Long(\"2499\"),\n min: Long(\"235\"),\n sumOfSquares: Decimal128(\"6422726\")\n },\n docsReturned: {\n sum: Long(\"3\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"3\")\n },\n firstSeenTimestamp: ISODate(\"2023-11-29T21:16:17.796Z\"),\n latestSeenTimestamp: ISODate(\"2023-11-29T21:17:12.385Z\")\n },\n asOf: Timestamp({ t: 1701292827, i: 0 })\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">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryShape</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cmdNs</span>: <!-- -->{ <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">'test'</span>, <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">'products'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command</span>: <span class="lg-highlight-string">'find'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter</span>: <!-- -->{ <span class="lg-highlight-attr">item</span>: <!-- -->{ <span class="lg-highlight-string">'$eq'</span>: <span class="lg-highlight-string">'?string'</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">client</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">driver</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'nodejs|mongosh'</span>, <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">os</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'Darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">architecture</span>: <span class="lg-highlight-string">'arm64'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'22.6.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">platform</span>: <span class="lg-highlight-string">'Node.js v16.19.1, LE (unified)'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0|1.8.0'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">application</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'mongosh 1.8.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">collectionType</span>: <span class="lg-highlight-string">'collection'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyHash</span>: <span class="lg-highlight-string">'dsoJ+LHAru0z6MJ1/IygJnnLTrlpVYYmPnlmNZbZrLI='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metrics</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastExecutionMicros</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">execCount</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-attr">totalExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"18096516"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstResponseExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"18096516"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsReturned</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</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-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"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">firstSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-09-14T12:30:27.989Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">latestSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-09-14T12:30:27.989Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">asOf</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<!-- -->{ <span class="lg-highlight-attr">t</span>: <span class="lg-highlight-number">1694695007</span>, <span class="lg-highlight-attr">i</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">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryShape</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cmdNs</span>: <!-- -->{ <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">'test'</span>, <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">'products'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command</span>: <span class="lg-highlight-string">'aggregate'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">'$match'</span>: <!-- -->{ <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-string">'$gt'</span>: <span class="lg-highlight-string">'?number'</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">apiVersion</span>: <span class="lg-highlight-string">'1'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">client</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">driver</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'nodejs|mongosh'</span>, <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">os</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'Darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">architecture</span>: <span class="lg-highlight-string">'arm64'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'22.6.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">platform</span>: <span class="lg-highlight-string">'Node.js v16.19.1, LE (unified)'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0|1.8.0'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">application</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'mongosh 1.8.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">collectionType</span>: <span class="lg-highlight-string">'collection'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cursor</span>: <!-- -->{ <span class="lg-highlight-attr">batchSize</span>: <span class="lg-highlight-string">'?number'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyHash</span>: <span class="lg-highlight-string">'2QLBfL0m1lliStdN4XvBjqVBtZQ6ffaB2L1pJ99twT8='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metrics</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastExecutionMicros</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"350"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">execCount</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3084"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"2499"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"235"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"6422726"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstResponseExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3084"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"2499"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"235"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"6422726"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsReturned</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"3"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-29T21:16:17.796Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">latestSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-29T21:17:12.385Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">asOf</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<!-- -->{ <span class="lg-highlight-attr">t</span>: <span class="lg-highlight-number">1701292827</span>, <span class="lg-highlight-attr">i</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>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-queryStats-example-transformed">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Transformed Example
<a class="headerlink leafygreen-ui-1kepx47" href="#transformed-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="transformed-example">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Input:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.getSiblingDB(\"admin\").aggregate( [\n {\n $queryStats: {\n transformIdentifiers: {\n algorithm: \"hmac-sha-256\" ,\n hmacKey: BinData(8, \"87c4082f169d3fef0eef34dc8e23458cbb457c3sf3n2\")\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-title lg-highlight-function">getSiblingDB</span>(<span class="lg-highlight-string">"admin"</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">$queryStats</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">transformIdentifiers</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">algorithm</span>: <span class="lg-highlight-string">"hmac-sha-256"</span> <!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">hmacKey</span>: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">8</span>, <span class="lg-highlight-string">"87c4082f169d3fef0eef34dc8e23458cbb457c3sf3n2"</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 {\n key: {\n queryShape: {\n cmdNs: {\n db: 'Mtrt3iG7dsX5c5uCSIhSVlcu5qD3u3xx2EQnS1dJLxM=',\n coll: '3oJE6AyOuf8h5NqWiXETxulFlPm3QUXbMnMjL2EqAU4='\n },\n command: 'find',\n filter: {\n 'VWVRow7Ure92ajRPfrpWiU8OtDeWcLePFIq0+tooBng=': { '$eq': '?string' }\n }\n },\n client: {\n driver: { name: 'nodejs|mongosh', version: '5.1.0' },\n os: {\n type: 'Darwin',\n name: 'darwin',\n architecture: 'arm64',\n version: '22.6.0'\n },\n platform: 'Node.js v16.19.1, LE (unified)',\n version: '5.1.0|1.8.0',\n application: { name: 'mongosh 1.8.0' }\n },\n collectionType: 'collection'\n },\n keyHash: 'q4vxam+wbk8tTrl8D0MDFH1LQAbI8fWspfkGKhEUROk=',\n metrics: {\n lastExecutionMicros: Long(\"4254\"),\n execCount: Long(\"1\"),\n keysExamined: {\n sum: Int(\"5\"),\n max: Long(\"5\"),\n min: Long(\"5\"),\n sumOfSquares: Decimal128(\"25\")\n },\n docsExamined: {\n sum: Long(\"1\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"1\")\n },\n hasSortStage: false,\n usedDisk: false,\n fromMultiPlanner: false,\n fromPlanCache: true,\n totalExecMicros: {\n sum: Long(\"4254\"),\n max: Long(\"4254\"),\n min: Long(\"4254\"),\n sumOfSquares: Decimal128(\"18096516\")\n },\n firstResponseExecMicros: {\n sum: Long(\"4254\"),\n max: Long(\"4254\"),\n min: Long(\"4254\"),\n sumOfSquares: Decimal128(\"18096516\")\n },\n docsReturned: {\n sum: Long(\"1\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"1\")\n },\n firstSeenTimestamp: ISODate(\"2023-09-14T12:30:27.989Z\"),\n latestSeenTimestamp: ISODate(\"2023-09-14T12:30:27.989Z\")\n },\n asOf: Timestamp({ t: 1694695712, i: 0 })\n },\n {\n key: {\n queryShape: {\n cmdNs: {\n db: 'Mtrt3iG7dsX5c5uCSIhSVlcu5qD3u3xx2EQnS1dJLxM=',\n coll: '3oJE6AyOuf8h5NqWiXETxulFlPm3QUXbMnMjL2EqAU4='\n },\n command: 'aggregate',\n pipeline: [\n {\n '$match': {\n 'RVqrwNEPotzdKnma/T7s4YcgNvpqO29BMDoni2N4IMI=': { '$gt': '?number' }\n }\n }\n ]\n },\n apiVersion: '1',\n client: {\n driver: { name: 'nodejs|mongosh', version: '5.1.0' },\n os: {\n type: 'Darwin',\n name: 'darwin',\n architecture: 'arm64',\n version: '22.6.0'\n },\n platform: 'Node.js v16.19.1, LE (unified)',\n version: '5.1.0|1.8.0',\n application: { name: 'mongosh 1.8.0' }\n },\n collectionType: 'collection',\n cursor: { batchSize: '?number' }\n },\n keyHash: 'HEhpQTYB+/wVoHLkOkMd+EC2jguQlMJ1N/vTE7+b8Js=',\n metrics: {\n lastExecutionMicros: Long(\"350\"),\n execCount: Long(\"3\"),\n keysExamined: {\n sum: Int(\"5\"),\n max: Long(\"5\"),\n min: Long(\"5\"),\n sumOfSquares: Decimal128(\"25\")\n },\n docsExamined: {\n sum: Long(\"1\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"1\")\n },\n hasSortStage: false,\n usedDisk: false,\n fromMultiPlanner: false,\n fromPlanCache: true,\n totalExecMicros: {\n sum: Long(\"3084\"),\n max: Long(\"2499\"),\n min: Long(\"235\"),\n sumOfSquares: Decimal128(\"6422726\")\n },\n firstResponseExecMicros: {\n sum: Long(\"3084\"),\n max: Long(\"2499\"),\n min: Long(\"235\"),\n sumOfSquares: Decimal128(\"6422726\")\n },\n docsReturned: {\n sum: Long(\"3\"),\n max: Long(\"1\"),\n min: Long(\"1\"),\n sumOfSquares: Decimal128(\"3\")\n },\n firstSeenTimestamp: ISODate(\"2023-11-29T21:16:17.796Z\"),\n latestSeenTimestamp: ISODate(\"2023-11-29T21:17:12.385Z\")\n },\n asOf: Timestamp({ t: 1701293302, i: 0 })\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"> <!-- -->{</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">queryShape</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cmdNs</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">'Mtrt3iG7dsX5c5uCSIhSVlcu5qD3u3xx2EQnS1dJLxM='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">'3oJE6AyOuf8h5NqWiXETxulFlPm3QUXbMnMjL2EqAU4='</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command</span>: <span class="lg-highlight-string">'find'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">filter</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">'VWVRow7Ure92ajRPfrpWiU8OtDeWcLePFIq0+tooBng='</span>: <!-- -->{ <span class="lg-highlight-string">'$eq'</span>: <span class="lg-highlight-string">'?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"> <span class="lg-highlight-attr">client</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">driver</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'nodejs|mongosh'</span>, <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">os</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'Darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">architecture</span>: <span class="lg-highlight-string">'arm64'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'22.6.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">platform</span>: <span class="lg-highlight-string">'Node.js v16.19.1, LE (unified)'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0|1.8.0'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">application</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'mongosh 1.8.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">collectionType</span>: <span class="lg-highlight-string">'collection'</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyHash</span>: <span class="lg-highlight-string">'q4vxam+wbk8tTrl8D0MDFH1LQAbI8fWspfkGKhEUROk='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metrics</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastExecutionMicros</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">execCount</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-attr">keysExamined</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Int</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"25"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsExamined</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</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-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"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">hasSortStage</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">usedDisk</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fromMultiPlanner</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fromPlanCache</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"18096516"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstResponseExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"4254"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"18096516"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsReturned</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</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-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"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">firstSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-09-14T12:30:27.989Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">latestSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-09-14T12:30:27.989Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">asOf</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<!-- -->{ <span class="lg-highlight-attr">t</span>: <span class="lg-highlight-number">1694695712</span>, <span class="lg-highlight-attr">i</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">key</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">queryShape</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cmdNs</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">db</span>: <span class="lg-highlight-string">'Mtrt3iG7dsX5c5uCSIhSVlcu5qD3u3xx2EQnS1dJLxM='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">coll</span>: <span class="lg-highlight-string">'3oJE6AyOuf8h5NqWiXETxulFlPm3QUXbMnMjL2EqAU4='</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">command</span>: <span class="lg-highlight-string">'aggregate'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pipeline</span>: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">'$match'</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">'RVqrwNEPotzdKnma/T7s4YcgNvpqO29BMDoni2N4IMI='</span>: <!-- -->{ <span class="lg-highlight-string">'$gt'</span>: <span class="lg-highlight-string">'?number'</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">apiVersion</span>: <span class="lg-highlight-string">'1'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">client</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">driver</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'nodejs|mongosh'</span>, <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0'</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">os</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">'Darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'darwin'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">architecture</span>: <span class="lg-highlight-string">'arm64'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'22.6.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">platform</span>: <span class="lg-highlight-string">'Node.js v16.19.1, LE (unified)'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">version</span>: <span class="lg-highlight-string">'5.1.0|1.8.0'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">application</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">'mongosh 1.8.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">collectionType</span>: <span class="lg-highlight-string">'collection'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">cursor</span>: <!-- -->{ <span class="lg-highlight-attr">batchSize</span>: <span class="lg-highlight-string">'?number'</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keyHash</span>: <span class="lg-highlight-string">'HEhpQTYB+/wVoHLkOkMd+EC2jguQlMJ1N/vTE7+b8Js='</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">metrics</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lastExecutionMicros</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"350"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">execCount</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">keysExamined</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Int</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"5"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"25"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsExamined</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</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-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"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">hasSortStage</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">usedDisk</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fromMultiPlanner</span>: <span class="lg-highlight-literal">false</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">fromPlanCache</span>: <span class="lg-highlight-literal">true</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">totalExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3084"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"2499"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"235"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"6422726"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstResponseExecMicros</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3084"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"2499"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">min</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"235"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"6422726"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">docsReturned</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sum</span>: <span class="lg-highlight-title lg-highlight-class">Long</span>(<span class="lg-highlight-string">"3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">max</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-attr">min</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-attr">sumOfSquares</span>: <span class="lg-highlight-title lg-highlight-class">Decimal128</span>(<span class="lg-highlight-string">"3"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">firstSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-29T21:16:17.796Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">latestSeenTimestamp</span>: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2023-11-29T21:17:12.385Z"</span>)</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">asOf</span>: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<!-- -->{ <span class="lg-highlight-attr">t</span>: <span class="lg-highlight-number">1701293302</span>, <span class="lg-highlight-attr">i</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>
</div>
</div>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
MongoDB Atlas Data Collection
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-atlas-data-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="mongodb-atlas-data-collection">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB Atlas periodically uses
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
to collect anonymized
data about your queries, which helps improve MongoDB products. Your data
may also be used to make feature suggestions based on usage. MongoDB
retains the data it collects with
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
for four years.
</p>
<p class="leafygreen-ui-1kp3ins">
When Atlas runs
<code class="leafygreen-ui-1l06pbn">
$queryStats
</code>
on your deployment, it uses a unique
HMAC key per Atlas organization to transform your data and avoid
collecting sensitive information.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/mongo/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
Shell
<a class="headerlink leafygreen-ui-1kepx47" href="#legacy-mongo-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="legacy-mongo-shell">
</div>
</a>
</h1>
<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
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell has been deprecated in MongoDB v5.0. The
replacement is
<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">
Older
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell documentation is included with the
corresponding documentation for that
<code class="leafygreen-ui-1l06pbn">
MongoDB
</code>
release.
</p>
<p class="leafygreen-ui-1kp3ins">
For the legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell documentation, refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/legacy/?site=docs" target="_self">
<span>
legacy documentation
</span>
</a>
for the corresponding MongoDB Server release.
</p>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/KeyVault.addKeyName/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
KeyVault.addKeyAltName()
<a class="headerlink leafygreen-ui-1kepx47" href="#keyvault.addkeyaltname--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.addkeyaltname--">
</div>
</a>
</h1>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
KeyVault.addKeyAltName(UUID, keyAltName)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-KeyVault.addKeyAltName" 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.addKeyAltName">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds the
<code class="leafygreen-ui-1l06pbn">
keyAltName
</code>
to the
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
array of the data
encryption key with
<code class="leafygreen-ui-1l06pbn">
UUID
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
keyAltName
</code>
<em>
must
</em>
be unique among all keys in the key vault.
</p>
<p class="leafygreen-ui-1kp3ins">
Use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/getKeyVault/#mongodb-method-getKeyVault">
<code class="leafygreen-ui-1l06pbn">
getKeyVault()
</code>
</a>
method with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-partial/#std-label-index-type-partial">
partial index
</a>
filter on documents with
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
to
automatically create a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
on
the
<code class="leafygreen-ui-1l06pbn">
keyAltNames
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
This method is an alias for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.addKeyAlternateName/#mongodb-method-KeyVault.addKeyAlternateName">
<code class="leafygreen-ui-1l06pbn">
addKeyAlternateName()
</code>
.
</a>
</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">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/KeyVault.addKeyAlternateName/#mongodb-method-KeyVault.addKeyAlternateName">
<code class="leafygreen-ui-1l06pbn">
addKeyAlternateName()
</code>
.
</a>
</p>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/setParameter/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
setParameter
<a class="headerlink leafygreen-ui-1kepx47" href="#setparameter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="setparameter">
</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>
</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">
setParameter
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.setParameter" 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.setParameter">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</span>
</a>
is an administrative command for
modifying options normally set on the command line. You must issue
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
setParameter
</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>
<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 <parameter>: <value>\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"> <<!-- -->parameter<!-- -->><!-- -->: <<!-- -->value<!-- -->></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 the available parameters, including examples, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/">
MongoDB Server Parameters for a Self-Managed Deployment
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-setParameter-commands-not-persistent">
</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>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Persistence
<a class="headerlink leafygreen-ui-1kepx47" href="#persistence" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="persistence">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Commands issued by the admin command
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</span>
</a>
do not survive server restarts. For a persistent option use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--setParameter">
<code class="leafygreen-ui-1l06pbn">
--setParameter
</code>
</a>
command line option
or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-setParameter">
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</a>
configuration file setting.
</p>
</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 with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/stable-api/#std-label-api-strict-desc">
apiStrict
</a>
set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, you cannot use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.setParameter" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
setParameter
</code>
</span>
</a>
to modify server parameters.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.rotateCertificates/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.rotateCertificates()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.rotatecertificates--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.rotatecertificates--">
</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="#output" target="_self">
<span>
Output
</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="#logging" target="_self">
<span>
Logging
</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>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates(message)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.rotateCertificates" 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.rotateCertificates">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Rotates the currently used
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-rotated-certs-method" target="_self">
<span>
TLS certificates
</span>
</a>
for a
<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>
to use the updated values for these
certificates defined in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/">
configuration file
<!-- -->
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.rotateCertificates(message)","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">rotateCertificates</span>(<!-- -->message)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method takes the following
optional argument:
</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">
message
</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.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method wraps the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/rotateCertificates/#mongodb-dbcommand-dbcmd.rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
command.
</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-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">
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-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method returns a document with
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">
ok
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
bool
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Contains the command's execution status.
<code class="leafygreen-ui-1l06pbn">
true
</code>
on success, or
<code class="leafygreen-ui-1l06pbn">
false
</code>
if an error occurred. If
<code class="leafygreen-ui-1l06pbn">
false
</code>
, an
<code class="leafygreen-ui-1l06pbn">
errmsg
</code>
field
is additionally provided with a detailed error message.
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rotated-certs-method">
</span>
<p class="leafygreen-ui-1kp3ins">
Rotation includes the following certificates:
</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-net.tls.certificateKeyFile">
<code class="leafygreen-ui-1l06pbn">
TLS Certificates
</code>
</a>
</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-net.tls.CRLFile">
<code class="leafygreen-ui-1l06pbn">
CRL (Certificate Revocation List) files
</code>
</a>
(on Linux and Windows platforms)
</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-net.tls.CAFile">
<code class="leafygreen-ui-1l06pbn">
CA (Certificate Authority) files
</code>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To rotate one or more of these certificates:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Replace the certificate or certificates you wish to rotate on the
filesystem, noting the following constraints:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Each new certificate must have the
<em>
same filename
</em>
and
<em>
same filepath
</em>
as the certificate it is replacing.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If rotating an encrypted
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFile">
<code class="leafygreen-ui-1l06pbn">
TLS Certificate
</code>
</a>
, its password must be the same as
the password for the old certificate (as specified to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.certificateKeyFilePassword">
<code class="leafygreen-ui-1l06pbn">
certificateKeyFilePassword
</code>
</a>
configuration file
setting). Certificate rotation does not support the interactive
password prompt.
</p>
</li>
</ul>
</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
<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>
instance that you wish to perform certificate
rotation on.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Run
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
to rotate the certificates 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>
or
<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>
</ol>
<p class="leafygreen-ui-1kp3ins">
When certificate rotation takes place:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Existing connections 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>
instance are not terminated, and will continue
to use the old certificates.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Any new connections will use the new certificates.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
If you have configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.ocspEnabled">
<code class="leafygreen-ui-1l06pbn">
OCSP
</code>
</a>
for your
deployment, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method will also fetch
stapled OCSP responses during rotation.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method may be run on 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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
regardless of replication
status.
</p>
<p class="leafygreen-ui-1kp3ins">
Only one instance of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/rotateCertificates/#mongodb-dbcommand-dbcmd.rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
may run on each
<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>
process at a time. Attempting to initiate a second
instance while one is already running will result in an error.
</p>
<p class="leafygreen-ui-1kp3ins">
Incorrect, expired, revoked, or missing certificate files will cause the
certificate rotation to fail, but will not invalidate the existing
TLS configuration or terminate the 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>
process.
</p>
<p class="leafygreen-ui-1kp3ins">
If 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>
is running with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--tlsCertificateSelector">
<code class="leafygreen-ui-1l06pbn">
--tlsCertificateSelector
</code>
</a>
set
to
<code class="leafygreen-ui-1l06pbn">
thumbprint
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
will fail and write
a warning message to the log file.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Logging
<a class="headerlink leafygreen-ui-1kepx47" href="#logging" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="logging">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
On successful rotation, the subject names, thumbprints, and the
validity period of the server and cluster certificate thumbprints are
logged to the configured
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-destinations">
log destination
</a>
. If
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
auditing
</a>
is
enabled, this information is also written to the audit log.
</p>
<p class="leafygreen-ui-1kp3ins">
On Linux and Windows platforms, if a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.tls.CRLFile">
<code class="leafygreen-ui-1l06pbn">
CRL file
</code>
</a>
is present, its thumbprint and validity period are
also logged to these locations.
</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-rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#std-label-security-user-actions">
action
</a>
in order to use the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.rotateCertificates" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.rotateCertificates()
</code>
</span>
</a>
method
<!-- -->
. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/privilege-actions/#mongodb-authaction-rotateCertificates">
<code class="leafygreen-ui-1l06pbn">
rotateCertificates
</code>
</a>
action is part of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/built-in-roles/#mongodb-authrole-hostManager">
<code class="leafygreen-ui-1l06pbn">
hostManager
</code>
</a>
role.
</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 following operation rotates the certificates on 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, after having made the appropriate
updates to the configuration file to specify the updated certificate
information:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.rotateCertificates()","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">rotateCertificates</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 performs the same as above, but also writes a custom log
message at rotation time to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-destinations">
log file
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/auditing/#std-label-auditing">
audit file
<!-- -->
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.rotateCertificates(\"message\": \"Rotating certificates\")","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">rotateCertificates</span>(<span class="lg-highlight-string">"message"</span>: <span class="lg-highlight-string">"Rotating certificates"</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/db.printCollectionStats/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.printCollectionStats()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.printcollectionstats--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.printcollectionstats--">
</div>
</a>
</h1>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.printCollectionStats()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.printCollectionStats" 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.printCollectionStats">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
method. Returns statistics from every collection separated by three
hyphen characters.
</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="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.printCollectionStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.printCollectionStats()
</code>
</span>
</a>
method run 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>
does
<strong>
not
</strong>
return
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-JSON">
JSON
</a>
. Use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.printCollectionStats" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.printCollectionStats()
</code>
</span>
</a>
for manual inspection, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
in scripts.
</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/collStats/">
collStats
</a>
</p>
</div>
</div>
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.hello/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.hello()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.hello--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.hello--">
</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="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.hello()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.hello" 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.hello">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
Returns a document that describes the role 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>
instance.
</p>
<p class="leafygreen-ui-1kp3ins">
If 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 a member of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
, then
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hello/#mongodb-data-hello.isWritablePrimary">
<code class="leafygreen-ui-1l06pbn">
isWritablePrimary
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hello/#mongodb-data-hello.secondary">
<code class="leafygreen-ui-1l06pbn">
secondary
</code>
</a>
fields report if the instance is the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
or if it is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
member of the replica set.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hello/#mongodb-dbcommand-dbcmd.hello">
<code class="leafygreen-ui-1l06pbn">
hello
</code>
</a>
for the complete documentation of
the output of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.hello" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.hello()
</code>
.
</span>
</a>
</p>
</div>
</div>
</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 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-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/method/db.getProfilingStatus/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.getProfilingStatus()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.getprofilingstatus--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.getprofilingstatus--">
</div>
</a>
</h1>
<dl class="method">
<dt>
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.getProfilingStatus" 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.getProfilingStatus">
</div>
</a>
</dt>
<dd>
<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 current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/profile/#mongodb-dbcommand-dbcmd.profile">
<code class="leafygreen-ui-1l06pbn">
profile
</code>
</a>
level,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpThresholdMs">
<code class="leafygreen-ui-1l06pbn">
slowOpThresholdMs
</code>
</a>
setting,
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpSampleRate">
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
</a>
setting.
<p class="leafygreen-ui-1kp3ins">
You can set a
<code class="leafygreen-ui-1l06pbn">
filter
</code>
to control which operations are logged by
the profiler. When set, any configured filters are also returned by
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.getProfilingStatus" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
</span>
</a>
, along with a
<code class="leafygreen-ui-1l06pbn">
note
</code>
explaining filter behavior.
</p>
<p class="leafygreen-ui-1kp3ins">
You can set the profiling filter with either:
</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/method/db.setProfilingLevel/#mongodb-method-db.setProfilingLevel">
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</a>
shell method, or
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.filter">
<code class="leafygreen-ui-1l06pbn">
operationProfiling.filter
</code>
</a>
configuration file option.
</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd>
</dl>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$pow (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-pow--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="-pow--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">
$pow
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-pow" 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.-pow">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Raises a number to the specified exponent and returns the result.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-pow" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$pow
</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":"{ $pow: [ <number>, <exponent> ] }","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">$pow</span>: <!-- -->[ <<!-- -->number<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->exponent<!-- -->> <!-- -->] }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<exponent>
</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.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot raise
<code class="leafygreen-ui-1l06pbn">
0
</code>
to a negative exponent.
</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">
$pow
</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">
$pow
</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">
If either 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">
$pow
</code>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
. If either argument resolves to
<code class="leafygreen-ui-1l06pbn">
NaN
</code>
,
<code class="leafygreen-ui-1l06pbn">
$pow
</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">
{ $pow: [ 5, 0 ] }
</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">
{ $pow: [ 5, 2 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
25
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $pow: [ 5, -2 ] }
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
0.04
</code>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $pow: [ -5, 0.5 ] }
</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>
</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 called
<code class="leafygreen-ui-1l06pbn">
quizzes
</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.quizzes.insertMany( [\n {\n _id : 1,\n scores : [\n { name : \"dave123\", score : 85 },\n { name : \"dave2\", score : 90 },\n { name : \"ahn\", score : 71 }\n ]\n },\n {\n _id : 2,\n scores : [\n { name : \"li\", quiz : 2, score : 96 },\n { name : \"annT\", score : 77 },\n { name : \"ty\", score : 82 }\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">quizzes</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-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->scores <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"dave123"</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">85</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"dave2"</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">90</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"ahn"</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">71</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"> <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->scores <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"li"</span>, <!-- -->quiz <!-- -->: <span class="lg-highlight-number">2</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">96</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"annT"</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">77</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <!-- -->name <!-- -->: <span class="lg-highlight-string">"ty"</span>, <!-- -->score <!-- -->: <span class="lg-highlight-number">82</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 example calculates the variance for each quiz:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.quizzes.aggregate( [\n { $project: { variance: { $pow: [ { $stdDevPop: \"$scores.score\" }, 2 ] } } }\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">quizzes</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">variance</span>: <!-- -->{ <span class="lg-highlight-attr">$pow</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$stdDevPop</span>: <span class="lg-highlight-string">"$scores.score"</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">
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, variance : 64.66666666666667 }\n{ _id : 2, variance : 64.66666666666667 }","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">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span>, <!-- -->variance <!-- -->: <span class="lg-highlight-number">64.66666666666667</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">2</span>, <!-- -->variance <!-- -->: <span class="lg-highlight-number">64.66666666666667</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/map-reduce-to-aggregation-pipeline/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Map-Reduce to Aggregation Pipeline
<a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce-to-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="map-reduce-to-aggregation-pipeline">
</div>
</a>
</h1>
<p class="leafygreen-ui-1kp3ins">
An
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
</a>
provides
better performance and usability than a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/">
map-reduce
</a>
operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Map-reduce operations can be rewritten 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>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For map-reduce operations that require custom functionality, MongoDB
provides 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. Use these operators to
define custom aggregation expressions in JavaScript.
</p>
<p class="leafygreen-ui-1kp3ins">
Map-reduce expressions can be re-written as shown in the following
sections.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Map-Reduce to Aggregation Pipeline Translation Table
<a class="headerlink leafygreen-ui-1kepx47" href="#map-reduce-to-aggregation-pipeline-translation-table" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-to-aggregation-pipeline-translation-table">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The table is only an approximate translation. For instance, the table
shows an approximate translation of
<code class="leafygreen-ui-1l06pbn">
mapFunction
</code>
using 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>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
However, the
<code class="leafygreen-ui-1l06pbn">
mapFunction
</code>
logic may require additional stages,
such as if the logic includes iteration over an array:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"function() {\n this.items.forEach(function(item){ emit(item.sku, 1); });\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-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">items</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">item</span>)<!-- -->{ <span class="lg-highlight-title lg-highlight-function">emit</span>(<!-- -->item.<span class="lg-highlight-property">sku</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>
<p class="leafygreen-ui-1kp3ins">
Then, the aggregation pipeline includes an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind">
<code class="leafygreen-ui-1l06pbn">
$unwind
</code>
</a>
and a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
:
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $unwind: \"$items \"},\n{ $project: { emits: { key: { \"$items.sku\" }, value: 1 } } },","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">$unwind</span>: <span class="lg-highlight-string">"$items "</span>}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">emits</span>: <!-- -->{ <span class="lg-highlight-attr">key</span>: <!-- -->{ <span class="lg-highlight-string">"$items.sku"</span> }<!-- -->, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-number">1</span> } } }<!-- -->,</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
emits
</code>
field in
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/project/#mongodb-pipeline-pipe.-project">
<code class="leafygreen-ui-1l06pbn">
$project
</code>
</a>
may be named something
else. For visual comparison, the field name
<code class="leafygreen-ui-1l06pbn">
emits
</code>
was chosen.
</p>
</li>
</ul>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:45%"/>
<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>
Map-Reduce
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Aggregation Pipeline
</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">
db.collection.mapReduce(
</div>
<div class="line-block">
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
<mapFunction>
</span>
,
</div>
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
{
</div>
<div class="line-block">
<div class="line">
query: <queryFilter>,
</div>
<div class="line">
sort: <sortOrder>,
</div>
<div class="line">
limit: <number>,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
out:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
<collection>
</span>
</div>
</div>
<div class="line">
}
</div>
</div>
<div class="line">
)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
db.collection.aggregate( [
</div>
<div class="line-block">
<div class="line">
{ $match: <queryFilter> },
</div>
<div class="line">
{ $sort: <sortOrder> },
</div>
<div class="line">
{ $limit: <number> },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$project: { emits: { k: <expression>, v: <expression> } }
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$unwind: "$emits"
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$group
</span>
: {
</div>
<div class="line-block">
<div class="line">
_id: "$emits.k"},
</div>
<div class="line">
value: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$accumulator
</span>
: {
</div>
<div class="line-block">
<div class="line">
init: <initCode>,
</div>
<div class="line">
accumulate:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
accumulateArgs: [ "$emit.v"],
</div>
<div class="line">
merge:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
lang: "js" }}
</div>
</div>
</div>
<div class="line">
} },
</div>
<div class="line">
{ $out:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
<collection>
</span>
}
</div>
</div>
<div class="line">
] )
</div>
</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">
db.collection.mapReduce(
</div>
<div class="line-block">
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
<mapFunction>
</span>
,
</div>
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
{
</div>
<div class="line-block">
<div class="line">
query: <queryFilter>,
</div>
<div class="line">
sort: <sortOrder>,
</div>
<div class="line">
limit: <number>,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
out: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
replace: <collection>, db:<db>
</span>
}
</div>
</div>
<div class="line">
}
</div>
</div>
<div class="line">
)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
db.collection.aggregate( [
</div>
<div class="line-block">
<div class="line">
{ $match: <queryFilter> },
</div>
<div class="line">
{ $sort: <sortOrder> },
</div>
<div class="line">
{ $limit: <number> },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$project: { emits: { k: <expression>, v: <expression> } }
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$unwind: "$emits"
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$group
</span>
: {
</div>
<div class="line-block">
<div class="line">
_id: "$emits.k"},
</div>
<div class="line">
value: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$accumulator
</span>
: {
</div>
<div class="line-block">
<div class="line">
init: <initCode>,
</div>
<div class="line">
accumulate:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
accumulateArgs: [ "$emit.v"],
</div>
<div class="line">
merge:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
lang: "js" }}
</div>
</div>
</div>
<div class="line">
} },
</div>
<div class="line">
{ $out: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
db: <db>, coll: <collection>
</span>
} }
</div>
</div>
<div class="line">
] )
</div>
</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">
db.collection.mapReduce(
</div>
<div class="line-block">
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
<mapFunction>
</span>
,
</div>
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
{
</div>
<div class="line-block">
<div class="line">
query: <queryFilter>,
</div>
<div class="line">
sort: <sortOrder>,
</div>
<div class="line">
limit: <number>,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
out: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
merge: <collection>, db: <db>
</span>
}
</div>
</div>
<div class="line">
}
</div>
</div>
<div class="line">
)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
db.collection.aggregate( [
</div>
<div class="line-block">
<div class="line">
{ $match: <queryFilter> },
</div>
<div class="line">
{ $sort: <sortOrder> },
</div>
<div class="line">
{ $limit: <number> },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$project: { emits: { k: <expression>, v: <expression> } }
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$unwind: "$emits"
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$group
</span>
: {
</div>
<div class="line-block">
<div class="line">
_id: "$emits.k"},
</div>
<div class="line">
value: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$accumulator
</span>
: {
</div>
<div class="line-block">
<div class="line">
init: <initCode>,
</div>
<div class="line">
accumulate:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
accumulateArgs: [ "$emit.v"],
</div>
<div class="line">
merge:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
lang: "js" }}
</div>
</div>
</div>
<div class="line">
} },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
$merge
</span>
: {
</div>
<div class="line-block">
<div class="line">
into: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
db: <db>, coll: <collection>
</span>
},
</div>
<div class="line">
on: "_id"
</div>
<div class="line">
whenMatched: "replace",
</div>
<div class="line">
whenNotMatched: "insert"
</div>
</div>
<div class="line">
} },
</div>
</div>
<div class="line">
] )
</div>
</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">
db.collection.mapReduce(
</div>
<div class="line-block">
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
<mapFunction>
</span>
,
</div>
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
{
</div>
<div class="line-block">
<div class="line">
query: <queryFilter>,
</div>
<div class="line">
sort: <sortOrder>,
</div>
<div class="line">
limit: <number>,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
out: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
reduce: <collection>, db: <db>
</span>
}
</div>
</div>
<div class="line">
}
</div>
</div>
<div class="line">
)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
db.collection.aggregate( [
</div>
<div class="line-block">
<div class="line">
{ $match: <queryFilter> },
</div>
<div class="line">
{ $sort: <sortOrder> },
</div>
<div class="line">
{ $limit: <number> },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$project: { emits: { k: <expression>, v: <expression> } }
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$unwind: "$emits"
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$group
</span>
: {
</div>
<div class="line-block">
<div class="line">
_id: "$emits.k"},
</div>
<div class="line">
value: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$accumulator
</span>
: {
</div>
<div class="line-block">
<div class="line">
init: <initCode>,
</div>
<div class="line">
accumulate:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
accumulateArgs: [ "$emit.v"],
</div>
<div class="line">
merge:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
lang: "js" }}
</div>
</div>
</div>
<div class="line">
} },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
$merge
</span>
: {
</div>
<div class="line-block">
<div class="line">
into: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E1F7FF">
db: <db>, coll: <collection>
</span>
},
</div>
<div class="line">
on: "_id"
</div>
<div class="line">
whenMatched: [
</div>
<div class="line-block">
<div class="line">
{ $project: {
</div>
<div class="line-block">
<div class="line">
value: { $function: {
</div>
<div class="line-block">
<div class="line">
body:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
args: [
</div>
<div class="line-block">
<div class="line">
"$_id",
</div>
<div class="line">
[ "$value", "$$new.value" ]
</div>
</div>
<div class="line">
],
</div>
<div class="line">
lang: "js"
</div>
</div>
<div class="line">
} }
</div>
</div>
<div class="line">
} }
</div>
</div>
<div class="line">
]
</div>
<div class="line">
whenNotMatched: "insert"
</div>
</div>
<div class="line">
} },
</div>
</div>
<div class="line">
] )
</div>
</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">
db.collection.mapReduce(
</div>
<div class="line-block">
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
<mapFunction>
</span>
,
</div>
<div class="line">
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
{
</div>
<div class="line-block">
<div class="line">
query: <queryFilter>,
</div>
<div class="line">
sort: <sortOrder>,
</div>
<div class="line">
limit: <number>,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
out: { inline: 1 }
</div>
</div>
<div class="line">
}
</div>
</div>
<div class="line">
)
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<div class="line-block">
<div class="line">
db.collection.aggregate( [
</div>
<div class="line-block">
<div class="line">
{ $match: <queryFilter> },
</div>
<div class="line">
{ $sort: <sortOrder> },
</div>
<div class="line">
{ $limit: <number> },
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$project: { emits: { k: <expression>, v: <expression> } }
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FFEAE5">
$unwind: "$emits"
</span>
},
</div>
<div class="line">
{
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$group
</span>
: {
</div>
<div class="line-block">
<div class="line">
_id: "$emits.k"},
</div>
<div class="line">
value: {
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
$accumulator
</span>
: {
</div>
<div class="line-block">
<div class="line">
init: <initCode>,
</div>
<div class="line">
accumulate:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
accumulateArgs: [ "$emit.v"],
</div>
<div class="line">
merge:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#FEF7DB">
<reduceFunction>
</span>
,
</div>
<div class="line">
finalize:
<span class="leafygreen-ui-1fku1pu" style="--background-color:#E3FCF7">
<finalizeFunction>
</span>
,
</div>
<div class="line">
lang: "js" }}
</div>
</div>
</div>
<div class="line">
} }
</div>
</div>
<div class="line">
] )
</div>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-mr-to-agg-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>
<p class="leafygreen-ui-1kp3ins">
Various map-reduce expressions can be rewritten using aggregation
pipeline operators, 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, without requiring custom functions. However, for illustrative
purposes, the following examples provide both alternatives.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-mr-to-agg-examples1">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Example 1
<a class="headerlink leafygreen-ui-1kepx47" href="#example-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="example-1">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following map-reduce operation on the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection groups
by the
<code class="leafygreen-ui-1l06pbn">
cust_id
</code>
, and calculates the sum of the
<code class="leafygreen-ui-1l06pbn">
price
</code>
for each
<code class="leafygreen-ui-1l06pbn">
cust_id
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mapFunction1 = function() {\n emit(this.cust_id, this.price);\n};\n\nvar reduceFunction1 = function(keyCustId, valuesPrices) {\n return Array.sum(valuesPrices);\n};\n\ndb.orders.mapReduce(\n mapFunction1,\n reduceFunction1,\n { out: \"map_reduce_example\" }\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> mapFunction1 <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-title lg-highlight-function">emit</span>(<span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">cust_id</span>, <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">price</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">var</span> reduceFunction1 <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">keyCustId, valuesPrices</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <span class="lg-highlight-title lg-highlight-class">Array</span>.<span class="lg-highlight-title lg-highlight-function">sum</span>(<!-- -->valuesPrices)<!-- -->;</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">mapReduce</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->mapFunction1<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reduceFunction1<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">out</span>: <span class="lg-highlight-string">"map_reduce_example"</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">
<strong>
Alternative 1: (Recommended)
</strong>
You can rewrite the operation into
an aggregation pipeline without translating the map-reduce function
to equivalent pipeline stages:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate([\n { $group: { _id: \"$cust_id\", value: { $sum: \"$price\" } } },\n { $out: \"agg_alternative_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">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"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$cust_id"</span>, <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$price"</span> } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$out</span>: <span class="lg-highlight-string">"agg_alternative_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">
<strong>
Alternative 2: (For illustrative purposes only)
</strong>
The
following aggregation pipeline provides a translation of the various
map-reduce functions, using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
to define custom
functions:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate( [\n { $project: { emit: { key: \"$cust_id\", value: \"$price\" } } }, // equivalent to the map function\n { $group: { // equivalent to the reduce function\n _id: \"$emit.key\",\n valuesPrices: { $accumulator: {\n init: function() { return 0; },\n initArgs: [],\n accumulate: function(state, value) { return state + value; },\n accumulateArgs: [ \"$emit.value\" ],\n merge: function(state1, state2) { return state1 + state2; },\n lang: \"js\"\n } }\n } },\n { $out: \"agg_alternative_2\" }\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">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">emit</span>: <!-- -->{ <span class="lg-highlight-attr">key</span>: <span class="lg-highlight-string">"$cust_id"</span>, <span class="lg-highlight-attr">value</span>: <span class="lg-highlight-string">"$price"</span> } } }<!-- -->, <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> equivalent to the </span><span class="lg-highlight-comment">map function</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-comment">//</span><span class="lg-highlight-comment"> equivalent to the </span><span class="lg-highlight-comment">reduce function</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$emit.key"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">valuesPrices</span>: <!-- -->{ <span class="lg-highlight-attr">$accumulator</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">init</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{ <span class="lg-highlight-keyword">return</span> <span class="lg-highlight-number">0</span>; <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">initArgs</span>: <!-- -->[<!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accumulate</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">state, value</span>)<!-- --> <!-- -->{ <span class="lg-highlight-keyword">return</span> <!-- -->state <!-- -->+ <!-- -->value<!-- -->; <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accumulateArgs</span>: <!-- -->[ <span class="lg-highlight-string">"$emit.value"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">merge</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">state1, state2</span>)<!-- --> <!-- -->{ <span class="lg-highlight-keyword">return</span> <!-- -->state1 <!-- -->+ <!-- -->state2<!-- -->; <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lang</span>: <span class="lg-highlight-string">"js"</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">$out</span>: <span class="lg-highlight-string">"agg_alternative_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>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
First, 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 outputs documents with an
<code class="leafygreen-ui-1l06pbn">
emit
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
emit
</code>
field is a document with the fields:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
key
</code>
that contains the
<code class="leafygreen-ui-1l06pbn">
cust_id
</code>
value for the document
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
value
</code>
that contains the
<code class="leafygreen-ui-1l06pbn">
price
</code>
value for the document
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"emit\" : { \"key\" : \"Ant O. Knee\", \"value\" : 25 } }\n{ \"_id\" : 2, \"emit\" : { \"key\" : \"Ant O. Knee\", \"value\" : 70 } }\n{ \"_id\" : 3, \"emit\" : { \"key\" : \"Busby Bee\", \"value\" : 50 } }\n{ \"_id\" : 4, \"emit\" : { \"key\" : \"Busby Bee\", \"value\" : 25 } }\n{ \"_id\" : 5, \"emit\" : { \"key\" : \"Busby Bee\", \"value\" : 50 } }\n{ \"_id\" : 6, \"emit\" : { \"key\" : \"Cam Elot\", \"value\" : 35 } }\n{ \"_id\" : 7, \"emit\" : { \"key\" : \"Cam Elot\", \"value\" : 25 } }\n{ \"_id\" : 8, \"emit\" : { \"key\" : \"Don Quis\", \"value\" : 75 } }\n{ \"_id\" : 9, \"emit\" : { \"key\" : \"Don Quis\", \"value\" : 55 } }\n{ \"_id\" : 10, \"emit\" : { \"key\" : \"Don Quis\", \"value\" : 25 } }","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">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">25</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">70</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">50</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">25</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">50</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Cam Elot"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">35</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Cam Elot"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">25</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Don Quis"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">75</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Don Quis"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">55</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"Don Quis"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <span class="lg-highlight-number">25</span> } }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Then, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
uses 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>
operator to add the emitted values:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"Don Quis\", \"valuesPrices\" : 155 }\n{ \"_id\" : \"Cam Elot\", \"valuesPrices\" : 60 }\n{ \"_id\" : \"Ant O. Knee\", \"valuesPrices\" : 95 }\n{ \"_id\" : \"Busby Bee\", \"valuesPrices\" : 125 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Don Quis"</span>, <span class="lg-highlight-string">"valuesPrices"</span> <!-- -->: <span class="lg-highlight-number">155</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Cam Elot"</span>, <span class="lg-highlight-string">"valuesPrices"</span> <!-- -->: <span class="lg-highlight-number">60</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"valuesPrices"</span> <!-- -->: <span class="lg-highlight-number">95</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"valuesPrices"</span> <!-- -->: <span class="lg-highlight-number">125</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Finally, 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>
writes the output to the collection
<code class="leafygreen-ui-1l06pbn">
agg_alternative_2
</code>
. Alternatively, you could use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/merge/#mongodb-pipeline-pipe.-merge">
<code class="leafygreen-ui-1l06pbn">
$merge
</code>
</a>
instead of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/out/#mongodb-pipeline-pipe.-out">
<code class="leafygreen-ui-1l06pbn">
$out
</code>
.
</a>
</p>
</li>
</ol>
<span class="leafygreen-ui-1qnjd6d" id="std-label-mr-to-agg-examples2">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Example 2
<a class="headerlink leafygreen-ui-1kepx47" href="#example-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="example-2">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following map-reduce operation on the
<code class="leafygreen-ui-1l06pbn">
orders
</code>
collection
groups by the
<code class="leafygreen-ui-1l06pbn">
item.sku
</code>
field and calculates the number of
orders and the total quantity ordered for each sku. The operation
then calculates the average quantity per order for each sku value
and merges the results into the output collection.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"var mapFunction2 = function() {\n for (var idx = 0; idx < this.items.length; idx++) {\n var key = this.items[idx].sku;\n var value = { count: 1, qty: this.items[idx].qty };\n\n emit(key, value);\n }\n};\n\nvar reduceFunction2 = function(keySKU, countObjVals) {\n reducedVal = { count: 0, qty: 0 };\n\n for (var idx = 0; idx < countObjVals.length; idx++) {\n reducedVal.count += countObjVals[idx].count;\n reducedVal.qty += countObjVals[idx].qty;\n }\n\n return reducedVal;\n};\n\nvar finalizeFunction2 = function (key, reducedVal) {\n reducedVal.avg = reducedVal.qty/reducedVal.count;\n return reducedVal;\n};\n\ndb.orders.mapReduce(\n mapFunction2,\n reduceFunction2,\n {\n out: { merge: \"map_reduce_example2\" },\n query: { ord_date: { $gte: new Date(\"2020-03-01\") } },\n finalize: finalizeFunction2\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> mapFunction2 <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">for</span> <!-- -->(<span class="lg-highlight-keyword">var</span> idx <!-- -->= <span class="lg-highlight-number">0</span>; <!-- -->idx <!-- -->< <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">items</span>.<span class="lg-highlight-property">length</span>; <!-- -->idx<!-- -->+<!-- -->+<!-- -->) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> key <!-- -->= <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">items</span>[<!-- -->idx].<span class="lg-highlight-property">sku</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">var</span> value <!-- -->= <!-- -->{ <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-variable lg-highlight-language">this</span>.<span class="lg-highlight-property">items</span>[<!-- -->idx].<span class="lg-highlight-property">qty</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-function">emit</span>(<!-- -->key<!-- -->, <!-- -->value)<!-- -->;</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> reduceFunction2 <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">keySKU, countObjVals</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedVal <!-- -->= <!-- -->{ <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">0</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> idx <!-- -->= <span class="lg-highlight-number">0</span>; <!-- -->idx <!-- -->< <!-- -->countObjVals.<span class="lg-highlight-property">length</span>; <!-- -->idx<!-- -->+<!-- -->+<!-- -->) <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedVal.<span class="lg-highlight-property">count</span> <!-- -->+<!-- -->= <!-- -->countObjVals<!-- -->[<!-- -->idx].<span class="lg-highlight-property">count</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedVal.<span class="lg-highlight-property">qty</span> <!-- -->+<!-- -->= <!-- -->countObjVals<!-- -->[<!-- -->idx].<span class="lg-highlight-property">qty</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">return</span> <!-- -->reducedVal<!-- -->;</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> finalizeFunction2 <!-- -->= <span class="lg-highlight-keyword lg-highlight-function">function</span> <!-- -->(<span class="lg-highlight-params">key, reducedVal</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reducedVal.<span class="lg-highlight-property">avg</span> <!-- -->= <!-- -->reducedVal.<span class="lg-highlight-property">qty</span>/<!-- -->reducedVal.<span class="lg-highlight-property">count</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <!-- -->reducedVal<!-- -->;</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">mapReduce</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->mapFunction2<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->reduceFunction2<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">out</span>: <!-- -->{ <span class="lg-highlight-attr">merge</span>: <span class="lg-highlight-string">"map_reduce_example2"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">ord_date</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-03-01"</span>) } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">finalize</span>: <!-- -->finalizeFunction2</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">
<strong>
Alternative 1: (Recommended)
</strong>
You can rewrite the operation into
an aggregation pipeline without translating the map-reduce function
to equivalent pipeline stages:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate( [\n { $match: { ord_date: { $gte: new Date(\"2020-03-01\") } } },\n { $unwind: \"$items\" },\n { $group: { _id: \"$items.sku\", qty: { $sum: \"$items.qty\" }, orders_ids: { $addToSet: \"$_id\" } } },\n { $project: { value: { count: { $size: \"$orders_ids\" }, qty: \"$qty\", avg: { $divide: [ \"$qty\", { $size: \"$orders_ids\" } ] } } } },\n { $merge: { into: \"agg_alternative_3\", on: \"_id\", whenMatched: \"replace\", whenNotMatched: \"insert\" } }\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">aggregate</span>( <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$match</span>: <!-- -->{ <span class="lg-highlight-attr">ord_date</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-03-01"</span>) } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unwind</span>: <span class="lg-highlight-string">"$items"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$items.sku"</span>, <span class="lg-highlight-attr">qty</span>: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$items.qty"</span> }<!-- -->, <span class="lg-highlight-attr">orders_ids</span>: <!-- -->{ <span class="lg-highlight-attr">$addToSet</span>: <span class="lg-highlight-string">"$_id"</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-attr">count</span>: <!-- -->{ <span class="lg-highlight-attr">$size</span>: <span class="lg-highlight-string">"$orders_ids"</span> }<!-- -->, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-string">"$qty"</span>, <span class="lg-highlight-attr">avg</span>: <!-- -->{ <span class="lg-highlight-attr">$divide</span>: <!-- -->[ <span class="lg-highlight-string">"$qty"</span>, <!-- -->{ <span class="lg-highlight-attr">$size</span>: <span class="lg-highlight-string">"$orders_ids"</span> } ] } } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$merge</span>: <!-- -->{ <span class="lg-highlight-attr">into</span>: <span class="lg-highlight-string">"agg_alternative_3"</span>, <span class="lg-highlight-attr">on</span>: <span class="lg-highlight-string">"_id"</span>, <span class="lg-highlight-attr">whenMatched</span>: <span class="lg-highlight-string">"replace"</span>, <span class="lg-highlight-attr">whenNotMatched</span>: <span class="lg-highlight-string">"insert"</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">
<strong>
Alternative 2: (For illustrative purposes only)
</strong>
The following
aggregation pipeline provides a translation of the various
map-reduce functions, using
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/accumulator/#mongodb-group-grp.-accumulator">
<code class="leafygreen-ui-1l06pbn">
$accumulator
</code>
</a>
to define custom
functions:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.orders.aggregate( [\n { $match: { ord_date: {$gte: new Date(\"2020-03-01\") } } },\n { $unwind: \"$items\" },\n { $project: { emit: { key: \"$items.sku\", value: { count: { $literal: 1 }, qty: \"$items.qty\" } } } },\n { $group: {\n _id: \"$emit.key\",\n value: { $accumulator: {\n init: function() { return { count: 0, qty: 0 }; },\n initArgs: [],\n accumulate: function(state, value) {\n state.count += value.count;\n state.qty += value.qty;\n return state;\n },\n accumulateArgs: [ \"$emit.value\" ],\n merge: function(state1, state2) {\n return { count: state1.count + state2.count, qty: state1.qty + state2.qty };\n },\n finalize: function(state) {\n state.avg = state.qty / state.count;\n return state;\n },\n lang: \"js\"}\n }\n } },\n { $merge: {\n into: \"agg_alternative_4\",\n on: \"_id\",\n whenMatched: \"replace\",\n whenNotMatched: \"insert\"\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">orders</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>: <!-- -->{ <span class="lg-highlight-attr">ord_date</span>: <!-- -->{<span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-03-01"</span>) } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$unwind</span>: <span class="lg-highlight-string">"$items"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$project</span>: <!-- -->{ <span class="lg-highlight-attr">emit</span>: <!-- -->{ <span class="lg-highlight-attr">key</span>: <span class="lg-highlight-string">"$items.sku"</span>, <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">count</span>: <!-- -->{ <span class="lg-highlight-attr">$literal</span>: <span class="lg-highlight-number">1</span> }<!-- -->, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-string">"$items.qty"</span> } } } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$group</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"$emit.key"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">value</span>: <!-- -->{ <span class="lg-highlight-attr">$accumulator</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">init</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<!-- -->)<!-- --> <!-- -->{ <span class="lg-highlight-keyword">return</span> <!-- -->{ <span class="lg-highlight-attr">count</span>: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">0</span> }<!-- -->; <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">initArgs</span>: <!-- -->[<!-- -->]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accumulate</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">state, value</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->state.<span class="lg-highlight-property">count</span> <!-- -->+<!-- -->= <!-- -->value.<span class="lg-highlight-property">count</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->state.<span class="lg-highlight-property">qty</span> <!-- -->+<!-- -->= <!-- -->value.<span class="lg-highlight-property">qty</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <!-- -->state<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">accumulateArgs</span>: <!-- -->[ <span class="lg-highlight-string">"$emit.value"</span> ]<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">merge</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">state1, state2</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <!-- -->{ <span class="lg-highlight-attr">count</span>: <!-- -->state1.<span class="lg-highlight-property">count</span> <!-- -->+ <!-- -->state2.<span class="lg-highlight-property">count</span>, <span class="lg-highlight-attr">qty</span>: <!-- -->state1.<span class="lg-highlight-property">qty</span> <!-- -->+ <!-- -->state2.<span class="lg-highlight-property">qty</span> }<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">finalize</span>: <span class="lg-highlight-keyword lg-highlight-function">function</span>(<span class="lg-highlight-params">state</span>)<!-- --> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->state.<span class="lg-highlight-property">avg</span> <!-- -->= <!-- -->state.<span class="lg-highlight-property">qty</span> <!-- -->/ <!-- -->state.<span class="lg-highlight-property">count</span>;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-keyword">return</span> <!-- -->state<!-- -->;</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->}<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">lang</span>: <span class="lg-highlight-string">"js"</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">$merge</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">into</span>: <span class="lg-highlight-string">"agg_alternative_4"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">on</span>: <span class="lg-highlight-string">"_id"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenMatched</span>: <span class="lg-highlight-string">"replace"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">whenNotMatched</span>: <span class="lg-highlight-string">"insert"</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>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<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 selects only those
documents with
<code class="leafygreen-ui-1l06pbn">
ord_date
</code>
greater than or equal to
<code class="leafygreen-ui-1l06pbn">
new
Date("2020-03-01")
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/unwind/#mongodb-pipeline-pipe.-unwind">
<code class="leafygreen-ui-1l06pbn">
$unwind
</code>
</a>
stage breaks down the document by
the
<code class="leafygreen-ui-1l06pbn">
items
</code>
array field to output a document for each array
element. For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"cust_id\" : \"Ant O. Knee\", \"ord_date\" : ISODate(\"2020-03-01T00:00:00Z\"), \"price\" : 25, \"items\" : { \"sku\" : \"oranges\", \"qty\" : 5, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 1, \"cust_id\" : \"Ant O. Knee\", \"ord_date\" : ISODate(\"2020-03-01T00:00:00Z\"), \"price\" : 25, \"items\" : { \"sku\" : \"apples\", \"qty\" : 5, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 2, \"cust_id\" : \"Ant O. Knee\", \"ord_date\" : ISODate(\"2020-03-08T00:00:00Z\"), \"price\" : 70, \"items\" : { \"sku\" : \"oranges\", \"qty\" : 8, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 2, \"cust_id\" : \"Ant O. Knee\", \"ord_date\" : ISODate(\"2020-03-08T00:00:00Z\"), \"price\" : 70, \"items\" : { \"sku\" : \"chocolates\", \"qty\" : 5, \"price\" : 10 }, \"status\" : \"A\" }\n{ \"_id\" : 3, \"cust_id\" : \"Busby Bee\", \"ord_date\" : ISODate(\"2020-03-08T00:00:00Z\"), \"price\" : 50, \"items\" : { \"sku\" : \"oranges\", \"qty\" : 10, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 3, \"cust_id\" : \"Busby Bee\", \"ord_date\" : ISODate(\"2020-03-08T00:00:00Z\"), \"price\" : 50, \"items\" : { \"sku\" : \"pears\", \"qty\" : 10, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 4, \"cust_id\" : \"Busby Bee\", \"ord_date\" : ISODate(\"2020-03-18T00:00:00Z\"), \"price\" : 25, \"items\" : { \"sku\" : \"oranges\", \"qty\" : 10, \"price\" : 2.5 }, \"status\" : \"A\" }\n{ \"_id\" : 5, \"cust_id\" : \"Busby Bee\", \"ord_date\" : ISODate(\"2020-03-19T00:00:00Z\"), \"price\" : 50, \"items\" : { \"sku\" : \"chocolates\", \"qty\" : 5, \"price\" : 10 }, \"status\" : \"A\" }\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-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-01T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">25</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-01T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">25</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"apples"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-08T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">70</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Ant O. Knee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-08T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">70</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"chocolates"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-08T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-08T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"pears"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-18T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">25</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">2.5</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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">"cust_id"</span> <!-- -->: <span class="lg-highlight-string">"Busby Bee"</span>, <span class="lg-highlight-string">"ord_date"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-03-19T00:00:00Z"</span>)<!-- -->, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">50</span>, <span class="lg-highlight-string">"items"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"sku"</span> <!-- -->: <span class="lg-highlight-string">"chocolates"</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">10</span> }<!-- -->, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">...</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
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 outputs documents with an
<code class="leafygreen-ui-1l06pbn">
emit
</code>
field. The
<code class="leafygreen-ui-1l06pbn">
emit
</code>
field is a document with the fields:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
key
</code>
that contains the
<code class="leafygreen-ui-1l06pbn">
items.sku
</code>
value
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
value
</code>
that contains a document with the
<code class="leafygreen-ui-1l06pbn">
qty
</code>
value and a
<code class="leafygreen-ui-1l06pbn">
count
</code>
value
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 1, \"emit\" : { \"key\" : \"oranges\", \"value\" : { \"count\" : 1, \"qty\" : 5 } } }\n{ \"_id\" : 1, \"emit\" : { \"key\" : \"apples\", \"value\" : { \"count\" : 1, \"qty\" : 5 } } }\n{ \"_id\" : 2, \"emit\" : { \"key\" : \"oranges\", \"value\" : { \"count\" : 1, \"qty\" : 8 } } }\n{ \"_id\" : 2, \"emit\" : { \"key\" : \"chocolates\", \"value\" : { \"count\" : 1, \"qty\" : 5 } } }\n{ \"_id\" : 3, \"emit\" : { \"key\" : \"oranges\", \"value\" : { \"count\" : 1, \"qty\" : 10 } } }\n{ \"_id\" : 3, \"emit\" : { \"key\" : \"pears\", \"value\" : { \"count\" : 1, \"qty\" : 10 } } }\n{ \"_id\" : 4, \"emit\" : { \"key\" : \"oranges\", \"value\" : { \"count\" : 1, \"qty\" : 10 } } }\n{ \"_id\" : 5, \"emit\" : { \"key\" : \"chocolates\", \"value\" : { \"count\" : 1, \"qty\" : 5 } } }\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-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"apples"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</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">2</span>, <span class="lg-highlight-string">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"chocolates"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"pears"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</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">"emit"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"key"</span> <!-- -->: <span class="lg-highlight-string">"chocolates"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">5</span> } } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">...</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
uses 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>
operator to add the emitted
<code class="leafygreen-ui-1l06pbn">
count
</code>
and
<code class="leafygreen-ui-1l06pbn">
qty
</code>
and calculate the
<code class="leafygreen-ui-1l06pbn">
avg
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : \"chocolates\", \"value\" : { \"count\" : 3, \"qty\" : 15, \"avg\" : 5 } }\n{ \"_id\" : \"oranges\", \"value\" : { \"count\" : 7, \"qty\" : 63, \"avg\" : 9 } }\n{ \"_id\" : \"carrots\", \"value\" : { \"count\" : 2, \"qty\" : 15, \"avg\" : 7.5 } }\n{ \"_id\" : \"apples\", \"value\" : { \"count\" : 4, \"qty\" : 35, \"avg\" : 8.75 } }\n{ \"_id\" : \"pears\", \"value\" : { \"count\" : 1, \"qty\" : 10, \"avg\" : 10 } }","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">"_id"</span> <!-- -->: <span class="lg-highlight-string">"chocolates"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">3</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">15</span>, <span class="lg-highlight-string">"avg"</span> <!-- -->: <span class="lg-highlight-number">5</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"oranges"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">63</span>, <span class="lg-highlight-string">"avg"</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-string">"carrots"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">2</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">15</span>, <span class="lg-highlight-string">"avg"</span> <!-- -->: <span class="lg-highlight-number">7.5</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"apples"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">35</span>, <span class="lg-highlight-string">"avg"</span> <!-- -->: <span class="lg-highlight-number">8.75</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-string">"pears"</span>, <span class="lg-highlight-string">"value"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-string">"count"</span> <!-- -->: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-string">"qty"</span> <!-- -->: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-string">"avg"</span> <!-- -->: <span class="lg-highlight-number">10</span> } }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Finally, 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>
writes the output to the
collection
<code class="leafygreen-ui-1l06pbn">
agg_alternative_4
</code>
. If an existing document has the same
key
<code class="leafygreen-ui-1l06pbn">
_id
</code>
as the new result, the operation overwrites the existing
document. If there is no existing document with the same key, the
operation inserts the document.
</p>
</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">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-commands-comparison/">
Aggregation Commands Comparison
</a>
</p>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$documentNumber (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-documentnumber--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="-documentnumber--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>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<dl class="group">
<dt>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-group-grp.-documentNumber" 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-group-grp.-documentNumber">
</div>
</a>
</dt>
<dd>
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Returns the position of a document (known as the document number) in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partition
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sortBy
</a>
field determines the document number. For
more information on how MongoDB compares fields with different types,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/bson-type-comparison-order/#std-label-bson-types-comparison-order">
BSON comparison order
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
returns a unique number for each document in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partition
</a>
, even if multiple
documents have identical
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sortBy
</a>
field
values in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partition
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
is only available in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
syntax:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ $documentNumber: { } }"}
</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">{ $documentNumber: { } }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
does not accept any parameters.
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
includes documents that have a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sortBy
</a>
field that is
<code class="leafygreen-ui-1l06pbn">
null
</code>
or missing.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/rank/#mongodb-group-grp.-rank">
<code class="leafygreen-ui-1l06pbn">
$rank
</code>
</a>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/denseRank/#mongodb-group-grp.-denseRank">
<code class="leafygreen-ui-1l06pbn">
$denseRank
</code>
</a>
return
the position of the documents based on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sortBy
</a>
field values.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
differs from
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/rank/#mongodb-group-grp.-rank">
<code class="leafygreen-ui-1l06pbn">
$rank
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/denseRank/#mongodb-group-grp.-denseRank">
<code class="leafygreen-ui-1l06pbn">
$denseRank
</code>
</a>
in how documents with identical
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sortBy
</a>
field values in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partition
</a>
are treated:
</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/rank/#mongodb-group-grp.-rank">
<code class="leafygreen-ui-1l06pbn">
$rank
</code>
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/denseRank/#mongodb-group-grp.-denseRank">
<code class="leafygreen-ui-1l06pbn">
$denseRank
</code>
</a>
return the same position (known
as the rank) for those documents.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
returns a unique position (known as the
document number) for those documents.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
See the example in
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-documentNumber-duplicate-null-missing-values-example" target="_self">
<span>
Document Number for Duplicate, Null, and Missing Values
<!-- -->
.
</span>
</a>
</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">
Document Number for Each State
<a class="headerlink leafygreen-ui-1kepx47" href="#document-number-for-each-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="document-number-for-each-state">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
cakeSales
</code>
collection that contains cake sales in the states
of California (
<code class="leafygreen-ui-1l06pbn">
CA
</code>
) and Washington (
<code class="leafygreen-ui-1l06pbn">
WA
</code>
):
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSales.insertMany( [\n { _id: 0, type: \"chocolate\", orderDate: new Date(\"2020-05-18T14:10:30Z\"),\n state: \"CA\", price: 13, quantity: 120 },\n { _id: 1, type: \"chocolate\", orderDate: new Date(\"2021-03-20T11:30:05Z\"),\n state: \"WA\", price: 14, quantity: 140 },\n { _id: 2, type: \"vanilla\", orderDate: new Date(\"2021-01-11T06:31:15Z\"),\n state: \"CA\", price: 12, quantity: 145 },\n { _id: 3, type: \"vanilla\", orderDate: new Date(\"2020-02-08T13:13:23Z\"),\n state: \"WA\", price: 13, quantity: 104 },\n { _id: 4, type: \"strawberry\", orderDate: new Date(\"2019-05-18T16:09:01Z\"),\n state: \"CA\", price: 41, quantity: 162 },\n { _id: 5, type: \"strawberry\", orderDate: new Date(\"2019-01-08T06:12:03Z\"),\n state: \"WA\", price: 43, quantity: 134 }\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">cakeSales</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">0</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">120</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">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">140</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">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">145</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">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">104</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">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">162</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">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</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">
This example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage to output the cake sales document
number for each
<code class="leafygreen-ui-1l06pbn">
state
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSales.aggregate( [\n {\n $setWindowFields: {\n partitionBy: \"$state\",\n sortBy: { quantity: -1 },\n output: {\n documentNumberForState: {\n $documentNumber: {}\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">cakeSales</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">$setWindowFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partitionBy</span>: <span class="lg-highlight-string">"$state"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">quantity</span>: <!-- -->-<span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documentNumberForState</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$documentNumber</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">
In the example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
partitionBy: "$state"
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partitions
</a>
the documents in the collection by
<code class="leafygreen-ui-1l06pbn">
state
</code>
. There are partitions for
<code class="leafygreen-ui-1l06pbn">
CA
</code>
and
<code class="leafygreen-ui-1l06pbn">
WA
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sortBy: { quantity: -1 }
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sorts
</a>
the documents in each partition by
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
in descending order (
<code class="leafygreen-ui-1l06pbn">
-1
</code>
), so the highest
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
is first.
</p>
</li>
</ul>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
output
</code>
sets the document number in a new field called
<code class="leafygreen-ui-1l06pbn">
documentNumberForState
</code>
shown in the following results.
<code class="leafygreen-ui-1l06pbn">
documentNumberForState
</code>
is unique within each
<code class="leafygreen-ui-1l06pbn">
state
</code>
partition.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 4, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-05-18T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 41, \"quantity\" : 162, \"documentNumberForState\" : 1 }\n{ \"_id\" : 2, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2021-01-11T06:31:15Z\"),\n \"state\" : \"CA\", \"price\" : 12, \"quantity\" : 145, \"documentNumberForState\" : 2 }\n{ \"_id\" : 0, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2020-05-18T14:10:30Z\"),\n \"state\" : \"CA\", \"price\" : 13, \"quantity\" : 120, \"documentNumberForState\" : 3 }\n{ \"_id\" : 1, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2021-03-20T11:30:05Z\"),\n \"state\" : \"WA\", \"price\" : 14, \"quantity\" : 140, \"documentNumberForState\" : 1 }\n{ \"_id\" : 5, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-01-08T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 43, \"quantity\" : 134, \"documentNumberForState\" : 2 }\n{ \"_id\" : 3, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2020-02-08T13:13:23Z\"),\n \"state\" : \"WA\", \"price\" : 13, \"quantity\" : 104, \"documentNumberForState\" : 3 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">162</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">1</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">145</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">2</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">120</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">3</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">140</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">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">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">2</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">104</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-documentNumber-duplicate-null-missing-values-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Document Number for Duplicate, Null, and Missing Values
<a class="headerlink leafygreen-ui-1kepx47" href="#document-number-for-duplicate--null--and-missing-values" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-number-for-duplicate--null--and-missing-values">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Create a
<code class="leafygreen-ui-1l06pbn">
cakeSalesWithDuplicates
</code>
collection where:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Cake sales are placed in the state of California (
<code class="leafygreen-ui-1l06pbn">
CA
</code>
) and
Washington (
<code class="leafygreen-ui-1l06pbn">
WA
</code>
).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Documents 6 to 8 have the same
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
and
<code class="leafygreen-ui-1l06pbn">
state
</code>
as document
5.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Document 9 has the same
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
and
<code class="leafygreen-ui-1l06pbn">
state
</code>
as document 4.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Document 10 has a
<code class="leafygreen-ui-1l06pbn">
null
</code>
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Document 11 is missing the
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSalesWithDuplicates.insertMany( [\n { _id: 0, type: \"chocolate\", orderDate: new Date(\"2020-05-18T14:10:30Z\"),\n state: \"CA\", price: 13, quantity: 120 },\n { _id: 1, type: \"chocolate\", orderDate: new Date(\"2021-03-20T11:30:05Z\"),\n state: \"WA\", price: 14, quantity: 140 },\n { _id: 2, type: \"vanilla\", orderDate: new Date(\"2021-01-11T06:31:15Z\"),\n state: \"CA\", price: 12, quantity: 145 },\n { _id: 3, type: \"vanilla\", orderDate: new Date(\"2020-02-08T13:13:23Z\"),\n state: \"WA\", price: 13, quantity: 104 },\n { _id: 4, type: \"strawberry\", orderDate: new Date(\"2019-05-18T16:09:01Z\"),\n state: \"CA\", price: 41, quantity: 162 },\n { _id: 5, type: \"strawberry\", orderDate: new Date(\"2019-01-08T06:12:03Z\"),\n state: \"WA\", price: 43, quantity: 134 },\n { _id: 6, type: \"strawberry\", orderDate: new Date(\"2020-01-08T06:12:03Z\"),\n state: \"WA\", price: 41, quantity: 134 },\n { _id: 7, type: \"strawberry\", orderDate: new Date(\"2020-01-01T06:12:03Z\"),\n state: \"WA\", price: 34, quantity: 134 },\n { _id: 8, type: \"strawberry\", orderDate: new Date(\"2020-01-02T06:12:03Z\"),\n state: \"WA\", price: 40, quantity: 134 },\n { _id: 9, type: \"strawberry\", orderDate: new Date(\"2020-05-11T16:09:01Z\"),\n state: \"CA\", price: 39, quantity: 162 },\n { _id: 10, type: \"strawberry\", orderDate: new Date(\"2020-05-11T16:09:01Z\"),\n state: \"CA\", price: 39, quantity: null },\n { _id: 11, type: \"strawberry\", orderDate: new Date(\"2020-05-11T16:09:01Z\"),\n state: \"CA\", price: 39 }\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">cakeSalesWithDuplicates</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">0</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">120</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">type</span>: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">140</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">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">145</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">type</span>: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">104</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">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">162</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">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</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">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">7</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-01-01T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">34</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">8</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-01-02T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">40</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">134</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">9</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">39</span>, <span class="lg-highlight-attr">quantity</span>: <span class="lg-highlight-number">162</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">39</span>, <span class="lg-highlight-attr">quantity</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-number">11</span>, <span class="lg-highlight-attr">type</span>: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-attr">orderDate</span>: <span class="lg-highlight-keyword">new</span> <span class="lg-highlight-title lg-highlight-class">Date</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-attr">price</span>: <span class="lg-highlight-number">39</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">
This example uses
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-group-grp.-documentNumber" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$documentNumber
</code>
</span>
</a>
in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#mongodb-pipeline-pipe.-setWindowFields">
<code class="leafygreen-ui-1l06pbn">
$setWindowFields
</code>
</a>
stage to output the
<code class="leafygreen-ui-1l06pbn">
cakeSalesWithDuplicates
</code>
document number for each
<code class="leafygreen-ui-1l06pbn">
state
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeSalesWithDuplicates.aggregate( [\n {\n $setWindowFields: {\n partitionBy: \"$state\",\n sortBy: { quantity: -1 },\n output: {\n documentNumberForState: {\n $documentNumber: {}\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">cakeSalesWithDuplicates</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">$setWindowFields</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">partitionBy</span>: <span class="lg-highlight-string">"$state"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sortBy</span>: <!-- -->{ <span class="lg-highlight-attr">quantity</span>: <!-- -->-<span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">output</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">documentNumberForState</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$documentNumber</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">
In the example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
partitionBy: "$state"
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-partitionBy">
partitions
</a>
the documents in the collection by
<code class="leafygreen-ui-1l06pbn">
state
</code>
. There are partitions for
<code class="leafygreen-ui-1l06pbn">
CA
</code>
and
<code class="leafygreen-ui-1l06pbn">
WA
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sortBy: { quantity: -1 }
</code>
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setWindowFields/#std-label-setWindowFields-sortBy">
sorts
</a>
the documents in each partition by
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
in descending order (
<code class="leafygreen-ui-1l06pbn">
-1
</code>
), so the highest
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
is first.
</p>
</li>
</ul>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
output
</code>
sets the document number in a new field called
<code class="leafygreen-ui-1l06pbn">
documentNumberForState
</code>
shown in the following results.
<code class="leafygreen-ui-1l06pbn">
documentNumberForState
</code>
is unique within each
<code class="leafygreen-ui-1l06pbn">
state
</code>
partition,
and there are
<code class="leafygreen-ui-1l06pbn">
documentNumberForState
</code>
values for documents with
<code class="leafygreen-ui-1l06pbn">
null
</code>
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
and missing
<code class="leafygreen-ui-1l06pbn">
quantity
</code>
values.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"_id\" : 4, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-05-18T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 41, \"quantity\" : 162, \"documentNumberForState\" : 1 }\n{ \"_id\" : 9, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-05-11T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 39, \"quantity\" : 162, \"documentNumberForState\" : 2 }\n{ \"_id\" : 2, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2021-01-11T06:31:15Z\"),\n \"state\" : \"CA\", \"price\" : 12, \"quantity\" : 145, \"documentNumberForState\" : 3 }\n{ \"_id\" : 0, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2020-05-18T14:10:30Z\"),\n \"state\" : \"CA\", \"price\" : 13, \"quantity\" : 120, \"documentNumberForState\" : 4 }\n{ \"_id\" : 10, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-05-11T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 39, \"quantity\" : null, \"documentNumberForState\" : 5 }\n{ \"_id\" : 11, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-05-11T16:09:01Z\"),\n \"state\" : \"CA\", \"price\" : 39, \"documentNumberForState\" : 6 }\n{ \"_id\" : 1, \"type\" : \"chocolate\", \"orderDate\" : ISODate(\"2021-03-20T11:30:05Z\"),\n \"state\" : \"WA\", \"price\" : 14, \"quantity\" : 140, \"documentNumberForState\" : 1 }\n{ \"_id\" : 5, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2019-01-08T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 43, \"quantity\" : 134, \"documentNumberForState\" : 2 }\n{ \"_id\" : 6, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-01-08T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 41, \"quantity\" : 134, \"documentNumberForState\" : 3 }\n{ \"_id\" : 7, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-01-01T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 34, \"quantity\" : 134, \"documentNumberForState\" : 4 }\n{ \"_id\" : 8, \"type\" : \"strawberry\", \"orderDate\" : ISODate(\"2020-01-02T06:12:03Z\"),\n \"state\" : \"WA\", \"price\" : 40, \"quantity\" : 134, \"documentNumberForState\" : 5 }\n{ \"_id\" : 3, \"type\" : \"vanilla\", \"orderDate\" : ISODate(\"2020-02-08T13:13:23Z\"),\n \"state\" : \"WA\", \"price\" : 13, \"quantity\" : 104, \"documentNumberForState\" : 6 }","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">"_id"</span> <!-- -->: <span class="lg-highlight-number">4</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-05-18T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">162</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">1</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">39</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">162</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">2</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-01-11T06:31:15Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">12</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">145</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">3</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">0</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-18T14:10:30Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">120</span>, <span class="lg-highlight-string">"documentNumberForState"</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">10</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">39</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-literal">null</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">5</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">{ <span class="lg-highlight-string">"_id"</span> <!-- -->: <span class="lg-highlight-number">11</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-05-11T16:09:01Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"CA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">39</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">6</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"chocolate"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2021-03-20T11:30:05Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">14</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">140</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">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">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2019-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">43</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">2</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-08T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">41</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">3</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-01T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">34</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"documentNumberForState"</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">8</span>, <span class="lg-highlight-string">"type"</span> <!-- -->: <span class="lg-highlight-string">"strawberry"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-01-02T06:12:03Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">40</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">134</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">5</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">"type"</span> <!-- -->: <span class="lg-highlight-string">"vanilla"</span>, <span class="lg-highlight-string">"orderDate"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">ISODate</span>(<span class="lg-highlight-string">"2020-02-08T13:13:23Z"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"WA"</span>, <span class="lg-highlight-string">"price"</span> <!-- -->: <span class="lg-highlight-number">13</span>, <span class="lg-highlight-string">"quantity"</span> <!-- -->: <span class="lg-highlight-number">104</span>, <span class="lg-highlight-string">"documentNumberForState"</span> <!-- -->: <span class="lg-highlight-number">6</span> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$toObjectId (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-toobjectid--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="-toobjectid--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">
$toObjectId
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-toObjectId" 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.-toObjectId">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Converts a value to an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/ObjectId/#mongodb-method-ObjectId">
<code class="leafygreen-ui-1l06pbn">
ObjectId()
</code>
</a>
. If the value cannot be
converted to an ObjectId,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toObjectId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toObjectId
</code>
</span>
</a>
errors. If the
value is null or missing,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toObjectId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toObjectId
</code>
</span>
</a>
returns null.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-toObjectId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toObjectId
</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 $toObjectId: <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">$toObjectId</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.-toObjectId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toObjectId
</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.-toObjectId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$toObjectId
</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: \"objectId\" } }","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">"objectId"</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 an
ObjectId:
</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>
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="">
<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">
Returns an ObjectId for the hexadecimal string of length 24.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot convert a string value that is not a hexadecimal
string of length 24.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
The following table lists some conversion to date examples:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:67%"/>
<col style="width:33%"/>
</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">
{$toObjectId: "5ab9cbfa31c2ab715d42129e"}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
ObjectId("5ab9cbfa31c2ab715d42129e")
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{$toObjectId: "5ab9cbfa31c2ab715d42129"}
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Error
</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: \"5ab9cbe531c2ab715d42129a\", item: \"apple\", qty: 10 },\n { _id: ObjectId(\"5ab9d0b831c2ab715d4212a8\"), item: \"pie\", qty: 5 },\n { _id: ObjectId(\"5ab9d2d331c2ab715d4212b3\"), item: \"ice cream\", qty: 20 },\n { _id: \"5ab9e16431c2ab715d4212b4\", item: \"almonds\", qty: 50 },\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-string">"5ab9cbe531c2ab715d42129a"</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">10</span> }<!-- -->,</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">"5ab9d0b831c2ab715d4212a8"</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">5</span> }<!-- -->,</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">"5ab9d2d331c2ab715d4212b3"</span>)<!-- -->, <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">"ice cream"</span>, <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">20</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-string">"5ab9e16431c2ab715d4212b4"</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">50</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">
_id
</code>
to ObjectId before sorting by the value:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Define stage to add convertedId field with converted _id value\n\nidConversionStage = {\n $addFields: {\n convertedId: { $toObjectId: \"$_id\" }\n }\n};\n\n// Define stage to sort documents by the converted qty values\n\nsortStage = {\n $sort: { \"convertedId\": -1 }\n};\n\n\ndb.orders.aggregate( [\n idConversionStage,\n sortStage\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 convertedId</span><span class="lg-highlight-comment"> field with converted </span><span class="lg-highlight-comment">_id value</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">idConversionStage <!-- -->= <!-- -->{</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">convertedId</span>: <!-- -->{ <span class="lg-highlight-attr">$toObjectId</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"><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">sort documents by</span><span class="lg-highlight-comment"> the converted qty </span><span class="lg-highlight-comment">values</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">sortStage <!-- -->= <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$sort</span>: <!-- -->{ <span class="lg-highlight-string">"convertedId"</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"><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">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"> <!-- -->idConversionStage<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->sortStage</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 documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n _id: '5ab9e16431c2ab715d4212b4',\n item: 'almonds',\n qty: 50,\n convertedId: ObjectId(\"5ab9e16431c2ab715d4212b4\")\n},\n{\n _id: ObjectId(\"5ab9d2d331c2ab715d4212b3\"),\n item: 'ice cream',\n qty: 20,\n convertedId: ObjectId(\"5ab9d2d331c2ab715d4212b3\")\n},\n{\n _id: ObjectId(\"5ab9d0b831c2ab715d4212a8\"),\n item: 'pie',\n qty: 5,\n convertedId: ObjectId(\"5ab9d0b831c2ab715d4212a8\")\n},\n{\n _id: '5ab9cbe531c2ab715d42129a',\n item: 'apple',\n qty: 10,\n convertedId: ObjectId(\"5ab9cbe531c2ab715d42129a\")\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">'5ab9e16431c2ab715d4212b4'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">'almonds'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">50</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">convertedId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9e16431c2ab715d4212b4"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9d2d331c2ab715d4212b3"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">'ice cream'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">20</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">convertedId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9d2d331c2ab715d4212b3"</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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9d0b831c2ab715d4212a8"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">item</span>: <span class="lg-highlight-string">'pie'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">qty</span>: <span class="lg-highlight-number">5</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">convertedId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9d0b831c2ab715d4212a8"</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-string">'5ab9cbe531c2ab715d42129a'</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <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">qty</span>: <span class="lg-highlight-number">10</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">convertedId</span>: <span class="lg-highlight-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"5ab9cbe531c2ab715d42129a"</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>
<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/reference/operator/aggregation/anyElementTrue/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
$anyElementTrue (aggregation)
<a class="headerlink leafygreen-ui-1kepx47" href="#-anyelementtrue--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="-anyelementtrue--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">
$anyElementTrue
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-expression-exp.-anyElementTrue" 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.-anyElementTrue">
</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 any of the
elements are
<code class="leafygreen-ui-1l06pbn">
true
</code>
and
<code class="leafygreen-ui-1l06pbn">
false
</code>
otherwise. An empty array
returns
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-expression-exp.-anyElementTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</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":"{ $anyElementTrue: [ <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">$anyElementTrue</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.-anyElementTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</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.-anyElementTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</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.-anyElementTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</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">
{ $anyElementTrue: [ [ true, 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">
{ $anyElementTrue: [ [ [ 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">
{ $anyElementTrue: [ [ 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>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
{ $anyElementTrue: [ [ ] ] }
</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.-anyElementTrue" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</code>
</span>
</a>
operator
to determine if the
<code class="leafygreen-ui-1l06pbn">
responses
</code>
array contains any value that
evaluates to
<code class="leafygreen-ui-1l06pbn">
true
</code>
:
</p>
<div class="css-1f5771r">
<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, isAnyTrue: { $anyElementTrue: [ \"$responses\" ] }, _id: 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">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">isAnyTrue</span>: <!-- -->{ <span class="lg-highlight-attr">$anyElementTrue</span>: <!-- -->[ <span class="lg-highlight-string">"$responses"</span> ] }<!-- -->, <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">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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="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 { _id: 1, responses: [ true ], isAnyTrue: true },\n { _id: 2, responses: [ true, false ], isAnyTrue: true },\n { _id: 3, responses: [], isAnyTrue: false },\n { _id: 4, responses: [ 1, true, 'seven' ], isAnyTrue: true },\n { _id: 5, responses: [ 0 ], isAnyTrue: false },\n { _id: 6, responses: [ [] ], isAnyTrue: true },\n { _id: 7, responses: [ [ 0 ] ], isAnyTrue: true },\n { _id: 8, responses: [ [ false ] ], isAnyTrue: true },\n { _id: 9, responses: [ null ], isAnyTrue: false },\n { _id: 10, responses: [ null ], isAnyTrue: false }\n]","programmingLanguage":"JavaScript"}
</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 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">responses</span>: <!-- -->[ <span class="lg-highlight-literal">true</span> ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</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">responses</span>: <!-- -->[ <span class="lg-highlight-literal">true</span>, <span class="lg-highlight-literal">false</span> ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</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">3</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[<!-- -->]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</span>: <span class="lg-highlight-literal">false</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">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-attr">isAnyTrue</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">5</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[ <span class="lg-highlight-number">0</span> ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</span>: <span class="lg-highlight-literal">false</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">responses</span>: <!-- -->[ <!-- -->[<!-- -->] ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</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">7</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-number">0</span> ] ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</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">8</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-literal">false</span> ] ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</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">9</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[ <span class="lg-highlight-literal">null</span> ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</span>: <span class="lg-highlight-literal">false</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">_id</span>: <span class="lg-highlight-number">10</span>, <span class="lg-highlight-attr">responses</span>: <!-- -->[ <span class="lg-highlight-literal">null</span> ]<!-- -->, <span class="lg-highlight-attr">isAnyTrue</span>: <span class="lg-highlight-literal">false</span> }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
In the results:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Document with
<code class="leafygreen-ui-1l06pbn">
_id: 1
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
because the element inside the
<code class="leafygreen-ui-1l06pbn">
responses
</code>
array evaluates as
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Documents with
<code class="leafygreen-ui-1l06pbn">
_id: 2
</code>
and
<code class="leafygreen-ui-1l06pbn">
_id: 4
</code>
are
<code class="leafygreen-ui-1l06pbn">
true
</code>
because at least
one element inside the
<code class="leafygreen-ui-1l06pbn">
responses
</code>
array evaluates as
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Documents with
<code class="leafygreen-ui-1l06pbn">
_id: 6
</code>
,
<code class="leafygreen-ui-1l06pbn">
_id: 7
</code>
, and
<code class="leafygreen-ui-1l06pbn">
_id: 8
</code>
are
<code class="leafygreen-ui-1l06pbn">
true
</code>
because the
<code class="leafygreen-ui-1l06pbn">
responses
</code>
array, which is the array that
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</code>
evaluated for the operation, contains a nested
array, which
<code class="leafygreen-ui-1l06pbn">
$anyElementTrue
</code>
always evaluates as
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
</ul>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/replica-configuration/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Self-Managed Replica Set Configuration
<a class="headerlink leafygreen-ui-1kepx47" href="#self-managed-replica-set-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="self-managed-replica-set-configuration">
</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="#replica-set-configuration-document-example" target="_self">
<span>
Replica Set Configuration Document Example
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#replica-set-configuration-fields" target="_self">
<span>
Replica Set Configuration Fields
</span>
</a>
</li>
</ul>
</div>
<p class="leafygreen-ui-1kp3ins">
You can access the configuration of a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
using 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 or 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">
To modify the configuration for a replica set, use the
<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>
method, passing a configuration document to the
method. See
<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>
for more information.
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-configuration-settings">
</span>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-configuration-document">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Replica Set Configuration Document Example
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-configuration-document-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="replica-set-configuration-document-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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replSetGetConfig-output">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Replica Set Configuration Fields
<a class="headerlink leafygreen-ui-1kepx47" href="#replica-set-configuration-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="replica-set-configuration-fields">
</div>
</a>
</h2>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
_id
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf._id" 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-rsconf-rsconf._id">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The name of the replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf._id" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
_id
</code>
</span>
</a>
<em>
must
</em>
be identical to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-replication.replSetName">
<code class="leafygreen-ui-1l06pbn">
replication.replSetName
</code>
</a>
or the value of
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
specified to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
on the command line.
</p>
<div class="leafygreen-ui-13vw3ie" role="note">
<h2 class="leafygreen-ui-1fn4p2b">
Tip
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
See:
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<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">
replSetName
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--replSet">
<code class="leafygreen-ui-1l06pbn">
--replSet
</code>
</a>
for information on setting the replica set name.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
version
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.version" 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-rsconf-rsconf.version">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
An incrementing number used to distinguish revisions of the replica
set configuration document from previous iterations of the
configuration.
</p>
<p class="leafygreen-ui-1kp3ins">
Replica set members use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.version" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
version
</code>
</span>
</a>
to
achieve consensus on the "newest" replica configuration. When
members compare replica configuration documents, the configuration
document with a larger
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
is considered the "newest".
If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
is the same or absent, the configuration
document with the larger
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.version" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
version
</code>
</span>
</a>
is considered "newest".
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
term
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.term" 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-rsconf-rsconf.term">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
Only available with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv">
featureCompatibilityVersion (fCV) "4.4"
</a>
or later.
</p>
<p class="leafygreen-ui-1kp3ins">
An incrementing number used to distinguish revisions of the replica
set configuration document from previous iterations of the
configuration. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
of a configuration document matches
the term of the replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
which performed the
reconfiguration. The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
increments its term each time it
steps up after winning an election. The primary ignores the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
field if set explicitly in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetReconfig/#mongodb-dbcommand-dbcmd.replSetReconfig">
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</a>
operation.
</p>
<p class="leafygreen-ui-1kp3ins">
Issuing a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetReconfig/#std-label-replSetReconfig-cmd-force">
force
</a>
reconfiguration
removes the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
field. When the primary next issues
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetReconfig/#mongodb-dbcommand-dbcmd.replSetReconfig">
<code class="leafygreen-ui-1l06pbn">
replSetReconfig
</code>
</a>
<em>
without
</em>
force, it sets the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
to its own term.
</p>
<p class="leafygreen-ui-1kp3ins">
Replica set members use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.version" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
version
</code>
</span>
</a>
to
achieve consensus on the "newest" replica configuration. When members
compare replica configuration documents, the configuration document
with a larger
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
is considered the "newest". If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.term" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
term
</code>
</span>
</a>
is the same or absent, the configuration document with
the larger
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.version" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
version
</code>
</span>
</a>
is considered "newest".
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
configsvr
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.configsvr" 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-rsconf-rsconf.configsvr">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
Indicates whether the replica set is used for a sharded cluster's
config servers. Set to
<code class="leafygreen-ui-1l06pbn">
true
</code>
if the replica set is for a sharded
cluster's config servers.
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
protocolVersion
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.protocolVersion" 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-rsconf-rsconf.protocolVersion">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: number
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 1
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB only supports
<code class="leafygreen-ui-1l06pbn">
protocolVersion: 1
</code>
and no longer supports
<code class="leafygreen-ui-1l06pbn">
protocolVersion: 0
</code>
.
</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/replica-set-protocol-versions/">
Self-Managed Replica Set Protocol Version
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" 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-rsconf-rsconf.writeConcernMajorityJournalDefault">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
Determines the behavior of
<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 if the write concern does not explicitly
specify the journal option
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-j">
j
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
The following table lists the
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
values and the associated
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#mongodb-writeconcern-writeconcern.-majority-">
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
</a>
behavior:
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:15%"/>
<col style="width:85%"/>
</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>
Value
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
<code class="leafygreen-ui-1l06pbn">
{ w: "majority" }
</code>
Behavior
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
true
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
MongoDB acknowledges the write operation after a majority of
the voting members have written to the on-disk journal.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-rws738">
IMPORTANT:
</strong>
All voting members of the replica set must
run with journaling when
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If any voting member of a replica set uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory
storage engine
</a>
, you must set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If any voting member of a replica set uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory
storage engine
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<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 may fail. These include
operations that inherently use
<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, such as the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetStepDown/#mongodb-dbcommand-dbcmd.replSetStepDown">
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</a>
command, or
various
<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 that by default use
<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, such as
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/js-user-management/">
user
management methods
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/js-role-management/">
role management methods
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set
member uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine
</a>
(voting or non-voting) but the replica set has
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
set to true, the
replica set member logs a startup warning.
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
false
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
MongoDB acknowledges the write operation after a majority of
the voting members have applied the operation in
memory.
</p>
<p class="leafygreen-ui-1kp3ins">
<strong class="css-4dei7l">
WARNING:
</strong>
</p>
<p class="leafygreen-ui-1kp3ins">
If any voting member of a replica set uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory
storage engine
</a>
, you must set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set
member uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory storage engine
</a>
(voting or non-voting) but the replica set has
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
set to true, the
replica set member logs a startup warning.
</p>
<p class="leafygreen-ui-1kp3ins">
You cannot run transactions on a sharded cluster that has a shard
with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.writeConcernMajorityJournalDefault" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
writeConcernMajorityJournalDefault
</code>
</span>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
(such as a shard with a voting member that uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/inmemory/#std-label-storage-inmemory">
in-memory
storage engine
</a>
).
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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/write-concern/#std-label-wc-ack-behavior">
Acknowledgment Behavior
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-set-protocol-versions/">
Self-Managed Replica Set Protocol Version
</a>
</p>
</li>
</ul>
</div>
</div>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-replica-set-configuration-buildIndexes">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
members
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#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="members">
</div>
</a>
</h3>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members" 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-rsconf-rsconf.members">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: array
</p>
<p class="leafygreen-ui-1kp3ins">
An array of member configuration documents, one for each member
of the replica set. The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members
</code>
</span>
</a>
array
is a zero-indexed array.
</p>
<p class="leafygreen-ui-1kp3ins">
Each member-specific configuration document can contain the following
fields:
</p>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n]._id
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-._id" 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-rsconf-rsconf.members-n-._id">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
An integer identifier for the member in the replica set, unique
among all members.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, values may be any integer value greater
than or equal to
<code class="leafygreen-ui-1l06pbn">
0
</code>
. Previously, this value was limited to an
integer between
<code class="leafygreen-ui-1l06pbn">
0
</code>
and
<code class="leafygreen-ui-1l06pbn">
255
</code>
inclusive.
</p>
<p class="leafygreen-ui-1kp3ins">
Each replica set member must have a unique
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-._id" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
_id
</code>
</span>
</a>
. Avoid re-using
<code class="leafygreen-ui-1l06pbn">
_id
</code>
values
<em>
even if
</em>
no
<code class="leafygreen-ui-1l06pbn">
members[n]
</code>
entry is using that
<code class="leafygreen-ui-1l06pbn">
_id
</code>
in
the current configuration.
</p>
<p class="leafygreen-ui-1kp3ins">
Once set, you cannot change the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-._id" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
_id
</code>
</span>
</a>
of a member.
</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">
When updating the replica configuration object, access the replica set
members in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members
</code>
</span>
</a>
array with the
<strong>
array index
</strong>
. The array index begins with
<code class="leafygreen-ui-1l06pbn">
0
</code>
. Do
<strong>
not
</strong>
confuse
this index value with the value of the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-._id" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n]._id
</code>
</span>
</a>
field in each document in
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members
</code>
</span>
</a>
array.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].host
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.host" 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-rsconf-rsconf.members-n-.host">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: string
</p>
<p class="leafygreen-ui-1kp3ins">
The hostname and, if specified, the port number, of the set
member.
</p>
<p class="leafygreen-ui-1kp3ins">
The hostname name must be resolvable for every host in the
replica set.
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.host" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].host
</code>
</span>
</a>
cannot hold a
value that resolves to
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
or the local interface
unless
<em>
all
</em>
members of the set are on hosts that resolve to
<code class="leafygreen-ui-1l06pbn">
localhost
</code>
.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].arbiterOnly
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.arbiterOnly" 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-rsconf-rsconf.members-n-.arbiterOnly">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
A boolean that identifies an arbiter. A value of
<code class="leafygreen-ui-1l06pbn">
true
</code>
indicates that the member is an arbiter.
</p>
<p class="leafygreen-ui-1kp3ins">
When using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.addArb/#mongodb-method-rs.addArb">
<code class="leafygreen-ui-1l06pbn">
rs.addArb()
</code>
</a>
method to add an arbiter,
the method automatically sets
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.arbiterOnly" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].arbiterOnly
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
true
</code>
for the added member.
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.buildIndexes" 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-rsconf-rsconf.members-n-.buildIndexes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
A boolean that indicates whether the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
builds
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-index">
indexes
</a>
on this member. You can only set this
value when adding a member to a replica set. You cannot change
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.buildIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
</span>
</a>
field after
the member has been added to the set. To add a member, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.add/#mongodb-method-rs.add">
<code class="leafygreen-ui-1l06pbn">
rs.add()
</code>
</a>
and
<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>
<p class="leafygreen-ui-1kp3ins">
Do not set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
for
<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 receive
queries from clients.
</p>
<p class="leafygreen-ui-1kp3ins">
Setting
<code class="leafygreen-ui-1l06pbn">
buildIndexes
</code>
to
<code class="leafygreen-ui-1l06pbn">
false
</code>
may be useful if
<strong>
all
</strong>
the following conditions are true:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
you are only using this instance to perform backups using
<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>
,
<em>
and
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
this member will receive no queries,
<em>
and
</em>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
index creation and maintenance overburdens the host
system.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Even if set to
<code class="leafygreen-ui-1l06pbn">
false
</code>
, secondaries
<em>
will
</em>
build indexes on the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in order to facilitate operations required for
replication.
</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 you set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.buildIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
false
</code>
, you must also set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.priority" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].priority
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0
</code>
. If
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.priority" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].priority
</code>
</span>
</a>
is not
<code class="leafygreen-ui-1l06pbn">
0
</code>
, MongoDB will return an error when attempting to add a
member with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.buildIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
</span>
</a>
equal to
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To ensure the member receives no queries, you should make all
instances that do not build indexes hidden.
</p>
<p class="leafygreen-ui-1kp3ins">
Other secondaries cannot replicate from a member where
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.buildIndexes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].buildIndexes
</code>
</span>
</a>
is
false.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].hidden
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.hidden" 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-rsconf-rsconf.members-n-.hidden">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: false
</p>
<p class="leafygreen-ui-1kp3ins">
When this value is
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the replica set hides this instance
and does not include the member in the output of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.hello/#mongodb-method-db.hello">
<code class="leafygreen-ui-1l06pbn">
db.hello()
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/hello/#mongodb-dbcommand-dbcmd.hello">
<code class="leafygreen-ui-1l06pbn">
hello
</code>
</a>
. This prevents
read operations (i.e. queries) from ever reaching this host by
way of secondary
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-read-preference">
read preference
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
Hidden members can acknowledge write operations
issued with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write Concern
</a>
. For write operations issued
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, the member must
also be a voting member (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
votes
</code>
</span>
</a>
is
greater than
<code class="leafygreen-ui-1l06pbn">
0
</code>
).
</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-hidden-member/#std-label-replica-set-hidden-members">
Hidden Replica Set Members
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].priority
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.priority" 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-rsconf-rsconf.members-n-.priority">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: Number between 0 and 1000 for primary/secondary; 0 or 1 for arbiters.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 1.0 for primary/secondary; 0 for arbiters.
</p>
<p class="leafygreen-ui-1kp3ins">
A number that indicates the relative likelihood of a replica set
member to become the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To increase the likelihood that a member becomes the primary,
specify a higher
<code class="leafygreen-ui-1l06pbn">
priority
</code>
value for that member.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To decrease the likelihood that a member becomes the primary,
specify a lower
<code class="leafygreen-ui-1l06pbn">
priority
</code>
value for that member.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Changing a member's priority triggers one or more elections. The
election algorithm makes a best-effort attempt to elect the
highest-priority member the primary. However, a lower-priority
member may become the primary even if a higher-priority secondary
is available.
</p>
<p class="leafygreen-ui-1kp3ins">
If a lower-priority member becomes the primary, the server
continues to periodically call elections until the
highest-priority replica set member is the primary. The frequency
at which the elections occur depends on the difference in priority
between the elected member and the highest-priority member.
</p>
<p class="leafygreen-ui-1kp3ins">
A member with a priority of
<code class="leafygreen-ui-1l06pbn">
0
</code>
cannot become the primary.
</p>
<p class="leafygreen-ui-1kp3ins">
Non-voting members (meaning members that have
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
votes
</code>
</span>
</a>
set to
<code class="leafygreen-ui-1l06pbn">
0
</code>
) must have a priority of
<code class="leafygreen-ui-1l06pbn">
0
</code>
.
</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/replica-set-elections/#std-label-replica-set-elections">
Replica Set Elections
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-rs-election-priority">
Member Priority
</a>
</p>
</li>
</ul>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].tags
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.tags" 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-rsconf-rsconf.members-n-.tags">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: document
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: none
</p>
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
tags
</code>
document contains user-defined tag field and value pairs for
the replica set member.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ \"<tag1>\": \"<string1>\", \"<tag2>\": \"<string2>\",... }","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">"<tag1>"</span>: <span class="lg-highlight-string">"<string1>"</span>, <span class="lg-highlight-string">"<tag2>"</span>: <span class="lg-highlight-string">"<string2>"</span>,<!-- -->...<!-- --> }</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For read operations, you can specify a tag set in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/read-preference-tags/#std-label-replica-set-read-preference-tag-sets">
read
preference
</a>
to direct the
operations to replica set member(s) with the specified tag(s).
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
For write operations, you can create a customize
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/">
write concern
</a>
using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.getLastErrorModes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorModes
</code>
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.getLastErrorDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorDefaults
</code>
.
</span>
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/configure-replica-set-tag-sets/">
Configure Replica Set Tag Sets
<!-- -->
.
</a>
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].secondaryDelaySecs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.secondaryDelaySecs" 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-rsconf-rsconf.members-n-.secondaryDelaySecs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 0
</p>
<p class="leafygreen-ui-1kp3ins">
The number of seconds "behind" the primary that this
replica set member should "lag".
</p>
<p class="leafygreen-ui-1kp3ins">
Use this option to create
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-delayed-member/#std-label-replica-set-delayed-members">
delayed members
</a>
. Delayed members maintain a copy
of the data that reflects the state of the data at some time in
the past.
</p>
<p class="leafygreen-ui-1kp3ins">
Delayed members can contribute to acknowledging write
operations issued with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
Write Concern
</a>
. However,
they return write acknowledgment no earlier than the configured
delay value. For write operations issued 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, the member must also be
a voting member (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
votes
</code>
</span>
</a>
is greater than
<code class="leafygreen-ui-1l06pbn">
0
</code>
).
</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-delayed-member/">
Delayed Replica Set Members
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
members[n].votes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.members-n-.votes" 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-rsconf-rsconf.members-n-.votes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: integer
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 1
</p>
<p class="leafygreen-ui-1kp3ins">
The number of votes a server will cast in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/#std-label-replica-set-elections">
replica set
election
</a>
. The number of votes each
member has is either
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
0
</code>
, and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-members/#std-label-replica-set-arbiters">
arbiters
</a>
always have exactly
<code class="leafygreen-ui-1l06pbn">
1
</code>
vote.
</p>
<p class="leafygreen-ui-1kp3ins">
Members with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.priority" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
priority
</code>
</span>
</a>
greater than 0 cannot have
0
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
votes
</code>
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
A replica set can have up to
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Number-of-Members-of-a-Replica-Set">
50 members
</a>
but only 7 voting members.
If you need more than 7 members in one replica set, set
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].votes
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0
</code>
for the
additional non-voting members.
</p>
<p class="leafygreen-ui-1kp3ins">
Non-voting (i.e.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.votes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
votes
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
0
</code>
) members must have
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.priority" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
priority
</code>
</span>
</a>
of 0.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, a newly added secondary does not count as
a voting member and cannot be elected until it has reached
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/replica-states/#mongodb-replstate-replstate.SECONDARY">
<code class="leafygreen-ui-1l06pbn">
SECONDARY
</code>
</a>
state.
</p>
<p class="leafygreen-ui-1kp3ins">
Non-voting members cannot acknowledge write operations
issued with a
<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.
</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/command/replSetGetStatus/#mongodb-data-replSetGetStatus.votingMembersCount">
<code class="leafygreen-ui-1l06pbn">
replSetGetStatus.votingMembersCount
</code>
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetGetStatus/#mongodb-data-replSetGetStatus.writableVotingMembersCount">
<code class="leafygreen-ui-1l06pbn">
replSetGetStatus.writableVotingMembersCount
</code>
</a>
</p>
</li>
</ul>
</div>
</div>
</dd>
</dl>
</dd>
</dl>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
settings
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#settings" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="settings">
</div>
</a>
</h3>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings" 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-rsconf-rsconf.settings">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: document
</p>
<p class="leafygreen-ui-1kp3ins">
A document that contains configuration options that apply to the
whole replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings
</code>
</span>
</a>
document contain the
following fields:
</p>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.chainingAllowed
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.chainingAllowed" 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-rsconf-rsconf.settings.chainingAllowed">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: boolean
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: true
</p>
<p class="leafygreen-ui-1kp3ins">
In MongoDB 5.0.1 and earlier, if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.chainingAllowed" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.chainingAllowed
</code>
</span>
</a>
is:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
true
</code>
, replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members can
replicate data from other secondary members.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
false
</code>
, secondary members can replicate data only from the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
<!-- -->
.
</a>
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0.2:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Replica set
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-secondary">
secondary
</a>
members can
replicate data from other secondary members even if
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.chainingAllowed" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.chainingAllowed
</code>
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To override
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.chainingAllowed" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.chainingAllowed
</code>
</span>
</a>
, set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.enableOverrideClusterChainingSetting">
<code class="leafygreen-ui-1l06pbn">
enableOverrideClusterChainingSetting
</code>
</a>
server
parameter to
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The default for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.enableOverrideClusterChainingSetting">
<code class="leafygreen-ui-1l06pbn">
enableOverrideClusterChainingSetting
</code>
</a>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</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/tutorial/manage-chained-replication/">
Self-Managed Chained Replication
</a>
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorDefaults
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.getLastErrorDefaults" 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-rsconf-rsconf.settings.getLastErrorDefaults">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: document
</p>
<p class="leafygreen-ui-1kp3ins">
Unavailable starting in MongoDB 5.0.
</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">
Starting in MongoDB 5.0, you cannot specify a default write concern with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.getLastErrorDefaults" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorDefaults
</code>
</span>
</a>
other than the default of
<code class="leafygreen-ui-1l06pbn">
{ w: 1, wtimeout: 0 }
</code>
. Instead, 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 to set the default read or
write concern configuration for a replica set or sharded cluster.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorModes
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.getLastErrorModes" 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-rsconf-rsconf.settings.getLastErrorModes">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: document
</p>
<p class="leafygreen-ui-1kp3ins">
A document used to define a custom
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
through the use of
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.members-n-.tags" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
members[n].tags
</code>
</span>
</a>
.
The custom write concern can provide
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-data-center-awareness">
data-center awareness
<!-- -->
.
</a>
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ getLastErrorModes: {\n <name> : { <tag1>: <number>, .... },\n ...\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">{ getLastErrorModes: {</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <name of write concern> : { <tag1>: <number>, .... },</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">
<number>
</code>
refers to the number of different tag values
required to satisfy the write concern. For example, the following
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.getLastErrorModes" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
settings.getLastErrorModes
</code>
</span>
</a>
defines a write concern
named
<code class="leafygreen-ui-1l06pbn">
datacenter
</code>
that requires the write to propagate to two
members whose
<code class="leafygreen-ui-1l06pbn">
dc
</code>
tag values differ.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ getLastErrorModes: { datacenter: { \"dc\": 2 } } }"}
</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">{ getLastErrorModes: { datacenter: { "dc": 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">
To use the custom write concern, pass in the write concern name
to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-wc-w">
<code class="leafygreen-ui-1l06pbn">
w
</code>
Option
</a>
, e.g.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ w: \"datacenter\" }"}
</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">{ w: "datacenter" }</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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/tutorial/configure-replica-set-tag-sets/">
Configure Replica Set Tag Sets
</a>
for more
information and example.
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.heartbeatTimeoutSecs
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.heartbeatTimeoutSecs" 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-rsconf-rsconf.settings.heartbeatTimeoutSecs">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 10
</p>
<p class="leafygreen-ui-1kp3ins">
Number of seconds that the replica set members wait for a
successful heartbeat from each other. If a member does not
respond in time, other members mark the delinquent member as
inaccessible.
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.electionTimeoutMillis
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.electionTimeoutMillis" 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-rsconf-rsconf.settings.electionTimeoutMillis">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 10000 (10 seconds)
</p>
<p class="leafygreen-ui-1kp3ins">
The time limit in milliseconds for detecting when a replica set's
primary is unreachable. This setting controls failover sensitivity
when using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.protocolVersion" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
protocolVersion: 1
</code>
</span>
</a>
. You can
expect the failover timeout to not exceed the value of
<code class="leafygreen-ui-1l06pbn">
electionTimeoutMillis
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider the following when selecting a value:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Higher values result in slower failovers but decreased
sensitivity to primary node or network slowness or spottiness.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Lower values result in faster failover but increased
sensitivity to primary node or network slowness or spottiness.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The setting only applies when using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.protocolVersion" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
protocolVersion: 1
</code>
.
</span>
</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">
When you step down a primary using
<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>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetStepDown/#mongodb-dbcommand-dbcmd.replSetStepDown">
<code class="leafygreen-ui-1l06pbn">
replSetStepDown
</code>
</a>
without setting the
<code class="leafygreen-ui-1l06pbn">
force
</code>
field to
<code class="leafygreen-ui-1l06pbn">
true
</code>
, the stepped-down primary nominates an eligible secondary
to call an election immediately.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.catchUpTimeoutMillis
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.catchUpTimeoutMillis" 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-rsconf-rsconf.settings.catchUpTimeoutMillis">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: -1, infinite catchup time.
</p>
<p class="leafygreen-ui-1kp3ins">
Time limit in milliseconds for a newly elected primary to sync
(catch up) with the other replica set members that may have more
recent writes. Infinite or high time limits may reduce the
amount of data that the other members would need to roll back
after an election but may increase the failover time.
</p>
<p class="leafygreen-ui-1kp3ins">
The newly elected primary ends the catchup period early once it
is fully caught up with other members of the set. During the
catchup period, the newly elected primary is unavailable for
writes from clients. Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetAbortPrimaryCatchUp/#mongodb-dbcommand-dbcmd.replSetAbortPrimaryCatchUp">
<code class="leafygreen-ui-1l06pbn">
replSetAbortPrimaryCatchUp
</code>
</a>
to abort the catchup then complete the transition to primary.
</p>
<p class="leafygreen-ui-1kp3ins">
The setting only applies when using
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.protocolVersion" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
protocolVersion: 1
</code>
.
</span>
</a>
</p>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-repl-conf-catchup-takeover-delay">
</span>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.catchUpTakeoverDelayMillis
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.catchUpTakeoverDelayMillis" 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-rsconf-rsconf.settings.catchUpTakeoverDelayMillis">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Optional
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: int
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Default
</em>
: 30000 (30 seconds)
</p>
<p class="leafygreen-ui-1kp3ins">
Time in milliseconds a node waits to initiate a
<em>
catchup takeover
</em>
after determining it is ahead of the current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
. During a catchup takeover, the node ahead of the
current primary initiates an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-election">
election
</a>
to become the new
primary of the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
After the node initiating the takeover determines that it is
ahead of the current
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary">
primary
</a>
, it waits the specified
number of milliseconds and then verifies the following:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
It is still ahead of the current primary,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
It is the most up-to-date node among all available nodes,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The current primary is currently catching up to it.
</p>
</li>
</ol>
<p class="leafygreen-ui-1kp3ins">
Once determining that all of these conditions are met, the node
initiating the takeover immediately runs for election.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on Replica
Set Elections, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-elections/">
Replica Set Elections
<!-- -->
.
</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">
Setting
<code class="leafygreen-ui-1l06pbn">
catchUpTakeoverDelayMillis
</code>
to
<code class="leafygreen-ui-1l06pbn">
-1
</code>
disables
catchup takeover. Setting
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.catchUpTimeoutMillis" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
catchUpTimeoutMillis
</code>
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0
</code>
disables
<em>
primary catchup
</em>
and consequently also catchup
takeover.
</p>
</div>
</div>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.heartbeatIntervalMillis
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.heartbeatIntervalMillis" 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-rsconf-rsconf.settings.heartbeatIntervalMillis">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Internal use only
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
The frequency in milliseconds of the heartbeats.
</p>
</dd>
</dl>
<dl class="rsconf">
<dt>
<code class="leafygreen-ui-1l06pbn">
settings.replicaSetId
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-rsconf-rsconf.settings.replicaSetId" 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-rsconf-rsconf.settings.replicaSetId">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
<em>
Type
</em>
: ObjectId
</p>
<p class="leafygreen-ui-1kp3ins">
The ObjectId associated with the replica set and automatically
created during
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/rs.initiate/#mongodb-method-rs.initiate">
<code class="leafygreen-ui-1l06pbn">
rs.initiate()
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/replSetInitiate/#mongodb-dbcommand-dbcmd.replSetInitiate">
<code class="leafygreen-ui-1l06pbn">
replSetInitiate
</code>
</a>
. You cannot change the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-rsconf-rsconf.settings.replicaSetId" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
replicaSetId
</code>
.
</span>
</a>
</p>
</dd>
</dl>
</dd>
</dl>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/rs.addArb/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
rs.addArb()
<a class="headerlink leafygreen-ui-1kepx47" href="#rs.addarb--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.addarb--">
</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="#ip-binding" target="_self">
<span>
IP Binding
</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.addArb(host)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-rs.addArb" 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.addArb">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
Adds a new
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter">
arbiter
</a>
to an existing replica set.
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
rs.add(<host>, true)
</code>
is functionally the same as
<code class="leafygreen-ui-1l06pbn">
rs.addArb(<host>)
</code>
. You can use these commands interchangeably.
</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 deploying more than one
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-arbiter">
arbiter
</a>
in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-replica-set">
replica set
</a>
. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/replica-set-arbiter/#std-label-rollbacks-multi-arbiters">
Concerns with Multiple Arbiters
<!-- -->
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To add an arbiter to an existing replica set:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Typically, if there are two or fewer data-bearing members in the
replica set, you might need to first set the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern">
cluster wide write
concern
</a>
for the replica set.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/setDefaultRWConcern/#std-label-set_global_default_write_concern">
cluster wide write concern
</a>
for more information on why you
might need to set the cluster wide write concern.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
You do not need to change the cluster wide write concern before starting
a new replica set with an arbiter.
</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/mongodb-defaults/#std-label-default-wc-formula">
Default write concern formula
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-rs.addArb" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
rs.addArb()
</code>
</span>
</a>
method takes 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>
Specifies the hostname and optionally the port number of the arbiter
member to add to replica set.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</dd>
</dl>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" 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>
</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 you bind your instance to a publicly-accessible IP address,
you must secure your cluster from unauthorized access. For a complete
list of security recommendations, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-security-checklist">
Security Checklist for Self-Managed Deployments
</a>
. At minimum, consider
<a class="leafygreen-ui-tqgtui" href="/docs/manual/administration/security-checklist/#std-label-checklist-auth">
enabling authentication
</a>
and
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/security-hardening/#std-label-network-config-hardening">
hardening
network infrastructure
<!-- -->
.
</a>
</p>
</div>
</div>
<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 localhost by default. If the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-net.ipv6">
<code class="leafygreen-ui-1l06pbn">
net.ipv6
</code>
</a>
configuration file
setting or the
<code class="leafygreen-ui-1l06pbn">
--ipv6
</code>
command line option is set for the binary,
the binary additionally binds to the localhost IPv6 address.
</p>
<p class="leafygreen-ui-1kp3ins">
By default
<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>
that are
bound to localhost only accept connections from clients that are
running on the same computer. This binding behavior includes
<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 other members of your replica set or sharded
cluster. Remote clients cannot connect to binaries that are bound only
to localhost.
</p>
<p class="leafygreen-ui-1kp3ins">
To override the default binding and bind to other IP addresses, use 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>
configuration file setting or the
<code class="leafygreen-ui-1l06pbn">
--bind_ip
</code>
command-line option to specify a list of hostnames or IP addresses.
</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">
Starting in MongDB 5.0,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://en.wikipedia.org/wiki/Split-horizon_DNS" rel="noopener noreferrer">
<span>
split horizon DNS
</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>
nodes that are
only configured with an IP address fail startup validation and
report an error. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.disableSplitHorizonIPCheck">
<code class="leafygreen-ui-1l06pbn">
disableSplitHorizonIPCheck
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
For example, 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>
instance binds to both
the localhost and the hostname
<code class="leafygreen-ui-1l06pbn">
My-Example-Associated-Hostname
</code>
, which is
associated with the IP address
<code class="leafygreen-ui-1l06pbn">
198.51.100.1
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongod --bind_ip localhost,My-Example-Associated-Hostname"}
</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">mongod --bind_ip localhost,My-Example-Associated-Hostname</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 order to connect to this instance, remote clients must specify
the hostname or its associated IP address
<code class="leafygreen-ui-1l06pbn">
198.51.100.1
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"mongosh --host My-Example-Associated-Hostname\n\nmongosh --host 198.51.100.1"}
</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">mongosh --host My-Example-Associated-Hostname</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><div class="leafygreen-ui-ihxujy"></div></td></tr><tr class=""><td class="leafygreen-ui-7razhx">mongosh --host 198.51.100.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>
<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>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/versioning/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
MongoDB Versioning
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-versioning" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-versioning">
</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="#lts-releases" target="_self">
<span>
Major
<!-- -->
Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#rapid-releases" target="_self">
<span>
Rapid Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#patch-releases" target="_self">
<span>
Patch Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#release-candidate--rc--releases" target="_self">
<span>
Release Candidate (RC) Releases
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#driver-versions" target="_self">
<span>
Driver Versions
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#mongodb-shell--mongosh-" target="_self">
<span>
MongoDB Shell (
<code class="css-1kekw28 e1wawog0">
mongosh
</code>
)
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#database-tools" target="_self">
<span>
Database Tools
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#historical-releases" target="_self">
<span>
Historical Releases
</span>
</a>
</li>
</ul>
</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">
Always upgrade to the latest stable patch release of your release series.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
MongoDB versioning has the form
<code class="leafygreen-ui-1l06pbn">
X.Y.Z
</code>
where
<code class="leafygreen-ui-1l06pbn">
X.Y
</code>
refers to the
release series and
<code class="leafygreen-ui-1l06pbn">
Z
</code>
refers to the patch number.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting with MongoDB 5.0, MongoDB is released as two different release
series:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Major
<!-- -->
Releases
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Rapid Releases
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For MongoDB 4.4 and previous, MongoDB used a Production / Development
versioning system. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-historical-releases" target="_self">
<span>
Historical Releases
<!-- -->
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-major-releases">
</span>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Major
<!-- -->
Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#lts-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="lts-releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Major
<!-- -->
Releases are made available approximately once a year, and
introduce new features and improvements.
<!-- -->
Major
<!-- -->
Releases are supported
for MongoDB Atlas and on-premises deployments.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Example versions:
</em>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.0
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
6.0
</code>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-rapid-releases">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Rapid Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#rapid-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="rapid-releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Rapid Releases are made available approximately once each quarter that
does not contain a
<!-- -->
Major
<!-- -->
Release, and introduce new features and
improvements. Rapid Releases are only supported within
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/atlas/database?tck=docs_server" target="_self">
<span>
MongoDB Atlas
</span>
</a>
, and are not
supported for on-premises deployments.
</p>
<p class="leafygreen-ui-1kp3ins">
Rapid Releases are not available for use with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://docs.opsmanager.mongodb.com/current/?tck=docs_server" target="_self">
<span>
MongoDB Ops Manager
</span>
</a>
.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Example versions:
</em>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.1
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.2
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.3
</code>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-versions-patch-release">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Patch Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#patch-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="patch-releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Patch Releases are made available as needed to both
<!-- -->
Major
<!-- -->
Releases and
Rapid Releases. Patch releases generally include bug fixes and minor
improvements.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Example versions:
</em>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.0.1
</code>
(a
<!-- -->
Major
<!-- -->
Release patch version)
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.2.1
</code>
(a Rapid Release patch version)
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Release Candidate (RC) Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#release-candidate--rc--releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="release-candidate--rc--releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
In advance of new
<!-- -->
Major
<!-- -->
Releases and Rapid Releases, Release Candidates
are made available for early testing. A Release Candidate represents a
version of the upcoming release that is stable enough to begin testing,
but is not suitable for production deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
<em>
Example versions:
</em>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.0.0-rc0
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.0.0-rc1
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
5.1.2-rc5
</code>
</p>
</li>
</ul>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Driver Versions
<a class="headerlink leafygreen-ui-1kepx47" href="#driver-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="driver-versions">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
The version numbering system for MongoDB differs from the system
used for the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/drivers/drivers/" target="_self">
<span>
MongoDB drivers
<!-- -->
.
</span>
</a>
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
MongoDB Shell (
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
)
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-shell--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="mongodb-shell--mongosh-">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
Starting with MongoDB 5.0, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/mongodb-shell/" target="_self">
<span>
MongoDB Shell
</span>
</a>
(
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
) is released separately from the MongoDB Server, and uses its
own version numbering system.
</p>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Database Tools
<a class="headerlink leafygreen-ui-1kepx47" href="#database-tools" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="database-tools">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/database-tools/" target="_self">
<span>
MongoDB Database Tools
</span>
</a>
are released separately
from the MongoDB Server, and use their own version numbering system.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-historical-releases">
</span>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Historical Releases
<a class="headerlink leafygreen-ui-1kepx47" href="#historical-releases" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="historical-releases">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For MongoDB 4.4 and previous, MongoDB versioning used a Production /
Development versioning scheme, and had the form
<code class="leafygreen-ui-1l06pbn">
X.Y.Z
</code>
where
<code class="leafygreen-ui-1l06pbn">
X.Y
</code>
refers to either a release series or development series and
<code class="leafygreen-ui-1l06pbn">
Z
</code>
refers
to the patch release number.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
Y
</code>
is even,
<code class="leafygreen-ui-1l06pbn">
X.Y
</code>
refers to a release series; for example,
<code class="leafygreen-ui-1l06pbn">
4.2
</code>
release series and
<code class="leafygreen-ui-1l06pbn">
4.4
</code>
release series. Release series are
<strong>
stable
</strong>
and suitable for production.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
Y
</code>
is odd,
<code class="leafygreen-ui-1l06pbn">
X.Y
</code>
refers to a development series; for example,
<code class="leafygreen-ui-1l06pbn">
4.3
</code>
development series and
<code class="leafygreen-ui-1l06pbn">
4.5
</code>
development series.
Development series are
<strong>
for testing only and not for production
</strong>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For example, in MongoDB version
<code class="leafygreen-ui-1l06pbn">
4.4.7
</code>
,
<code class="leafygreen-ui-1l06pbn">
4.4
</code>
refers to the
release series and
<code class="leafygreen-ui-1l06pbn">
.7
</code>
refers to the patch release.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/js-collection/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Collection Methods
<a class="headerlink leafygreen-ui-1kepx47" href="#collection-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="collection-methods">
</div>
</a>
</h1>
<div class="leafygreen-ui-15mdk4" role="note">
<h2 class="leafygreen-ui-6n7b7d">
Note
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
mongosh Methods
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
The methods listed on this table of contents page are
<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. This is
<em>
not
</em>
the documentation for
<code class="leafygreen-ui-1l06pbn">
Node.js
</code>
or other programming language specific driver methods.
</p>
<p class="leafygreen-ui-1kp3ins">
In most cases,
<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 work the same way as the
legacy
<code class="leafygreen-ui-1l06pbn">
mongo
</code>
shell methods. However, some legacy methods
are unavailable in
<code class="leafygreen-ui-1l06pbn">
mongosh
</code>
.
</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
</span>
</a>
documentation.
</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">
For details on a specific method, including syntax and examples,
click on the link to the method's reference page.
</p>
</div>
</div>
<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>
Name
</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/method/db.collection.analyzeShardKey/#mongodb-method-db.collection.analyzeShardKey">
<code class="leafygreen-ui-1l06pbn">
db.collection.analyzeShardKey()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Calculates metrics for evaluating a shard key.
</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.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>
Provides access to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
<!-- -->
.
</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/db.collection.bulkWrite/#mongodb-method-db.collection.bulkWrite">
<code class="leafygreen-ui-1l06pbn">
db.collection.bulkWrite()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Provides bulk write operation functionality.
</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.configureQueryAnalyzer/#mongodb-method-db.collection.configureQueryAnalyzer">
<code class="leafygreen-ui-1l06pbn">
db.collection.configureQueryAnalyzer()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Configures query sampling for a collection.
</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.count/#mongodb-method-db.collection.count">
<code class="leafygreen-ui-1l06pbn">
db.collection.count()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Wraps
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count">
<code class="leafygreen-ui-1l06pbn">
count
</code>
</a>
to return a count of the number of documents in a collection or a view.
</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.countDocuments/#mongodb-method-db.collection.countDocuments">
<code class="leafygreen-ui-1l06pbn">
db.collection.countDocuments()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Wraps the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
aggregation stage with a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/sum/#mongodb-group-grp.-sum">
<code class="leafygreen-ui-1l06pbn">
$sum
</code>
</a>
expression to return a count of the number of documents in a
collection or a view.
</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.createIndex/#mongodb-method-db.collection.createIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Builds an index on a collection.
</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.createIndexes/#mongodb-method-db.collection.createIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.createIndexes()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Builds one or more indexes on a collection.
</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.dataSize/#mongodb-method-db.collection.dataSize">
<code class="leafygreen-ui-1l06pbn">
db.collection.dataSize()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns the size of the collection. Wraps the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.size">
<code class="leafygreen-ui-1l06pbn">
size
</code>
</a>
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>
</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.deleteOne/#mongodb-method-db.collection.deleteOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.deleteOne()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Deletes a single document in a collection.
</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.deleteMany/#mongodb-method-db.collection.deleteMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.deleteMany()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Deletes multiple documents in a collection.
</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.distinct/#mongodb-method-db.collection.distinct">
<code class="leafygreen-ui-1l06pbn">
db.collection.distinct()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns an array of documents that have distinct values for the specified field.
</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.drop/#mongodb-method-db.collection.drop">
<code class="leafygreen-ui-1l06pbn">
db.collection.drop()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Removes the specified collection from the database.
</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.dropIndex/#mongodb-method-db.collection.dropIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.dropIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Removes a specified index on a collection.
</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.dropIndexes/#mongodb-method-db.collection.dropIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.dropIndexes()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Removes all indexes on a collection.
</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.ensureIndex/#mongodb-method-db.collection.ensureIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.ensureIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Removed. Use
<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>
</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.estimatedDocumentCount/#mongodb-method-db.collection.estimatedDocumentCount">
<code class="leafygreen-ui-1l06pbn">
db.collection.estimatedDocumentCount()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Wraps
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/count/#mongodb-dbcommand-dbcmd.count">
<code class="leafygreen-ui-1l06pbn">
count
</code>
</a>
to return an approximate count of the documents in a collection or a view.
</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.explain/#mongodb-method-db.collection.explain">
<code class="leafygreen-ui-1l06pbn">
db.collection.explain()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns information on the query execution of various methods.
</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>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs a query on a collection or a view and returns a cursor object.
</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.findAndModify/#mongodb-method-db.collection.findAndModify">
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Atomically modifies and returns a single document.
</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.findOne/#mongodb-method-db.collection.findOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOne()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs a query and returns a single document.
</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.findOneAndDelete/#mongodb-method-db.collection.findOneAndDelete">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndDelete()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Finds a single document and deletes it.
</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.findOneAndReplace/#mongodb-method-db.collection.findOneAndReplace">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndReplace()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Finds a single document and replaces it.
</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.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
db.collection.findOneAndUpdate()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Finds a single document and updates it.
</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.getIndexes/#mongodb-method-db.collection.getIndexes">
<code class="leafygreen-ui-1l06pbn">
db.collection.getIndexes()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns an array of documents that describe the existing indexes on a collection.
</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.getShardDistribution/#mongodb-method-db.collection.getShardDistribution">
<code class="leafygreen-ui-1l06pbn">
db.collection.getShardDistribution()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
For collections in sharded clusters,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.getShardDistribution/#mongodb-method-db.collection.getShardDistribution">
<code class="leafygreen-ui-1l06pbn">
db.collection.getShardDistribution()
</code>
</a>
reports data of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-chunk">
chunk
</a>
distribution.
</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.getShardVersion/#mongodb-method-db.collection.getShardVersion">
<code class="leafygreen-ui-1l06pbn">
db.collection.getShardVersion()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Internal diagnostic method for sharded cluster.
</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.hideIndex/#mongodb-method-db.collection.hideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.hideIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Hides an index from the query planner.
</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.insertOne/#mongodb-method-db.collection.insertOne">
<code class="leafygreen-ui-1l06pbn">
db.collection.insertOne()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Inserts a new document in a collection.
</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.insertMany/#mongodb-method-db.collection.insertMany">
<code class="leafygreen-ui-1l06pbn">
db.collection.insertMany()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Inserts several new document in a collection.
</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.isCapped/#mongodb-method-db.collection.isCapped">
<code class="leafygreen-ui-1l06pbn">
db.collection.isCapped()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Reports if a collection is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-capped-collection">
capped collection
<!-- -->
.
</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/db.collection.latencyStats/#mongodb-method-db.collection.latencyStats">
<code class="leafygreen-ui-1l06pbn">
db.collection.latencyStats()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Returns latency statistics for a collection.
</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.mapReduce/#mongodb-method-db.collection.mapReduce">
<code class="leafygreen-ui-1l06pbn">
db.collection.mapReduce()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs map-reduce style data aggregation.
</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.reIndex/#mongodb-method-db.collection.reIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.reIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Rebuilds all existing indexes on a collection.
</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.remove/#mongodb-method-db.collection.remove">
<code class="leafygreen-ui-1l06pbn">
db.collection.remove()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Deletes documents from a collection.
</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.renameCollection/#mongodb-method-db.collection.renameCollection">
<code class="leafygreen-ui-1l06pbn">
db.collection.renameCollection()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Changes the name of a collection.
</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.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 a single document in a collection.
</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.stats/#mongodb-method-db.collection.stats">
<code class="leafygreen-ui-1l06pbn">
db.collection.stats()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Reports on the state of a collection. Provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-dbcommand-dbcmd.collStats">
<code class="leafygreen-ui-1l06pbn">
collStats
</code>
.
</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/db.collection.storageSize/#mongodb-method-db.collection.storageSize">
<code class="leafygreen-ui-1l06pbn">
db.collection.storageSize()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Reports the total size used by the collection in bytes. Provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.storageSize">
<code class="leafygreen-ui-1l06pbn">
storageSize
</code>
</a>
field 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>
output.
</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.totalIndexSize/#mongodb-method-db.collection.totalIndexSize">
<code class="leafygreen-ui-1l06pbn">
db.collection.totalIndexSize()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Reports the total size used by the indexes on a collection. Provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/collStats/#mongodb-data-collStats.totalIndexSize">
<code class="leafygreen-ui-1l06pbn">
totalIndexSize
</code>
</a>
field 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>
output.
</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.totalSize/#mongodb-method-db.collection.totalSize">
<code class="leafygreen-ui-1l06pbn">
db.collection.totalSize()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Reports the total size of a collection, including the size of all documents and all indexes on a collection.
</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.unhideIndex/#mongodb-method-db.collection.unhideIndex">
<code class="leafygreen-ui-1l06pbn">
db.collection.unhideIndex()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Unhides an index from the query planner.
</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.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>
Modifies a single document in a collection.
</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.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>
Modifies multiple documents in a collection.
</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.watch/#mongodb-method-db.collection.watch">
<code class="leafygreen-ui-1l06pbn">
db.collection.watch()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Establishes a Change Stream on a collection.
</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.validate/#mongodb-method-db.collection.validate">
<code class="leafygreen-ui-1l06pbn">
db.collection.validate()
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs diagnostic operations on a collection.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</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">
To manage
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="https://www.mongodb.com/docs/atlas/atlas-search/atlas-search-overview/#fts-indexes" target="_self">
<span>
Atlas Search indexes
</span>
</a>
,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/js-atlas-search/#std-label-atlas-search-index-methods">
Atlas Search Index Methods
<!-- -->
.
</a>
</p>
</div>
</div>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/movePrimary/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
movePrimary
<a class="headerlink leafygreen-ui-1kepx47" href="#moveprimary" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="moveprimary">
</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>
<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="#additional-information" target="_self">
<span>
Additional Information
</span>
</a>
</li>
</ul>
</div>
<dl class="dbcommand">
<dt>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-dbcommand-dbcmd.movePrimary" 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.movePrimary">
</div>
</a>
</dt>
<dd>
<p class="leafygreen-ui-1kp3ins">
In a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-sharded-cluster">
sharded cluster
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
reassigns the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-primary-shard">
primary shard
</a>
which holds all un-sharded collections in
the database.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
first changes the primary shard in
the cluster metadata, and then migrates all un-sharded collections to the
specified
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard">
shard
</a>
. Use the command with the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { movePrimary: <databasename>, to: <newprimaryshard> } )","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">movePrimary</span>: <<!-- -->databaseName<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">to</span>: <<!-- -->newPrimaryShard<!-- -->> <!-- -->} )</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 example, the following command moves the primary shard from
<code class="leafygreen-ui-1l06pbn">
test
</code>
to
<code class="leafygreen-ui-1l06pbn">
shard0001
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.adminCommand( { movePrimary : \"test\", to : \"shard0001\" } )","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>( <!-- -->{ <!-- -->movePrimary <!-- -->: <span class="lg-highlight-string">"test"</span>, <!-- -->to <!-- -->: <span class="lg-highlight-string">"shard0001"</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 command returns, the database's primary shard location
has switched to the specified shard. To fully decommission a
shard, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/removeShard/#mongodb-dbcommand-dbcmd.removeShard">
<code class="leafygreen-ui-1l06pbn">
removeShard
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
is an administrative command that is only
available for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances.
</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">
After starting
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
, do
<strong>
not
</strong>
perform any
read or write operations against any unsharded collection in that
database until the command completes. Read or write operations
issued against those collections during the migration can result
in unexpected behavior, including potential failure of the
migration operation or loss of data.
</p>
</div>
</div>
</dd>
</dl>
<span class="leafygreen-ui-1qnjd6d" id="std-label-movePrimary-consideration">
</span>
<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 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>
<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>
write concern for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
.
</span>
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-movePrimary-maintenance-window">
</span>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Issue
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
During A Maintenance Window
<a class="headerlink leafygreen-ui-1kepx47" href="#issue-moveprimary-during-a-maintenance-window" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="issue-moveprimary-during-a-maintenance-window">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
may require a significant time to complete
depending on the size of the database and factors such as network health
or machine resources. Read or write operations issued against the
database during the migration can result in unexpected behavior,
including potential failure of the migration operation or loss of data.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider scheduling a maintenance window during which applications stop
all reads and writes to the cluster. Issuing
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
during planned downtime mitigates the risk of encountering undefined
behavior due to interleaving reads or writes to the unsharded
collections in the database.
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Namespace Conflicts Prevent Migration
<a class="headerlink leafygreen-ui-1kepx47" href="#namespace-conflicts-prevent-migration" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="namespace-conflicts-prevent-migration">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-dbcommand-dbcmd.movePrimary" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
</span>
</a>
fails if the destination shard contains a
conflicting collection namespace. For example:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An administrator issues
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
to change the
primary shard for the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A user or application issues a write operation against an unsharded
collection in
<code class="leafygreen-ui-1l06pbn">
hr
</code>
while
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
is moving that collection.
The write operation creates the collection in the original primary
shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
An administrator later issues
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
to restore
the original primary shard for the
<code class="leafygreen-ui-1l06pbn">
hr
</code>
database.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
fails due to the conflicting namespace
left behind from the interleaving write operation.
</p>
</li>
</ol>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Destination Shard Must Rebuild Indexes
<a class="headerlink leafygreen-ui-1kepx47" href="#destination-shard-must-rebuild-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="destination-shard-must-rebuild-indexes">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
As part of the
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
operation, the destination shard must
rebuild indexes on the migrated collections after becoming the primary
shard. This may require a significant amount of time depending on
the number of indexes per collection and the amount of data to index.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-creation/">
Index Builds on Populated Collections
</a>
for more information on the index
build process.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-movePrimary-change-streams">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Moving Collections that have Change Streams
<a class="headerlink leafygreen-ui-1kepx47" href="#moving-collections-that-have-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="moving-collections-that-have-change-streams">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 8.0,
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
doesn't
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/change-events/invalidate/#std-label-change-event-invalidate">
invalidate
</a>
collections that have
<a class="leafygreen-ui-tqgtui" href="/docs/manual/changeStreams/#std-label-changeStreams">
change
streams
</a>
. The change streams can continue to read events
from collections after the collections are moved to a new shard.
</p>
<p class="leafygreen-ui-1kp3ins">
In earlier MongoDB versions,
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
invalidates collection
change streams and the change streams cannot read events from the
collections.
</p>
<p class="leafygreen-ui-1kp3ins">
In all MongoDB versions,
<code class="leafygreen-ui-1l06pbn">
movePrimary
</code>
updates the
<span class="leafygreen-ui-vm4wms" tabindex="0">
UUID
</span>
for moved unsharded collections.
</p>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Additional Information
<a class="headerlink leafygreen-ui-1kepx47" href="#additional-information" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-information">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/remove-shards-from-cluster/">
Remove Shards from a Sharded Cluster
</a>
for a complete
procedure.
</p>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.setProfilingLevel/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.setProfilingLevel()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.setprofilinglevel--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.setprofilinglevel--">
</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-x9koo9" href="#syntax" target="_self">
<span>
Syntax
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#parameters" target="_self">
<span>
Parameters
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#returns" target="_self">
<span>
Returns
</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="#enable-profiler-and-set-slow-operation-threshold-and-sample-rate" target="_self">
<span>
Enable Profiler and Set Slow Operation Threshold and Sample Rate
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#disable-profiler-and-set-slow-operation-threshold-and-sample-rate" target="_self">
<span>
Disable Profiler and Set Slow Operation Threshold and Sample Rate
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#set-a-filter-to-determine-profiled-operations" target="_self">
<span>
Set a Filter to Determine Profiled Operations
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#unset-a-filter" target="_self">
<span>
Unset a Filter
</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.setProfilingLevel(level, options)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.setProfilingLevel" 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.setProfilingLevel">
</div>
</a>
</dt>
<dd>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
For a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#mongodb-binary-bin.mongod">
<code class="leafygreen-ui-1l06pbn">
mongod
</code>
</a>
instance, the method enables, disables,
or configures the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
Database Profiler
</a>
. The
profiler captures and records data on the performance of write
operations, cursors, and database commands on 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. If the profiler is disabled, the
method configures how slow operations are logged to the diagnostic
log.
</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">
Changes made to the profiling level with
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
do
<em>
not
</em>
persist. When the server restarts, it reverts to
<code class="leafygreen-ui-1l06pbn">
0
</code>
(the default), or the value set by either the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.mode">
<code class="leafygreen-ui-1l06pbn">
operationProfiling.mode
</code>
</a>
setting or the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--profile">
<code class="leafygreen-ui-1l06pbn">
--profile
</code>
</a>
command-line option.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
If the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
database profiler level
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
1
</code>
or
<code class="leafygreen-ui-1l06pbn">
2
</code>
(specifically, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
database profiler
</a>
is enabled), the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
affect
the behavior of both the profiler and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logpath">
<code class="leafygreen-ui-1l06pbn">
diagnostic log
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
database profiler level
</span>
</a>
is
<code class="leafygreen-ui-1l06pbn">
0
</code>
(specifically,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
database profiler
</a>
is disabled), the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
, affect
only the diagnostic log.
</p>
<p class="leafygreen-ui-1kp3ins">
With
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the
method sets the
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
,
<code class="leafygreen-ui-1l06pbn">
sampleRate
</code>
and
<code class="leafygreen-ui-1l06pbn">
filter
</code>
configuration settings, which configure how operations get written to
the diagnostic log. You cannot enable the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
Database Profiler
</a>
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 because
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
does not have any
collections that the profiler can write to. The
<code class="leafygreen-ui-1l06pbn">
profile
</code>
level
must be
<code class="leafygreen-ui-1l06pbn">
0
</code>
for 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 specify a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
</span>
</a>
on both
<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 to control which
operations are logged by the profiler. When you specify a
<code class="leafygreen-ui-1l06pbn">
filter
</code>
for the
profiler, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
, and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
options
are not used for profiling and slow-query log lines.
</p>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.setProfilingLevel" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</span>
</a>
provides a wrapper around the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/profile/#mongodb-dbcommand-dbcmd.profile">
<code class="leafygreen-ui-1l06pbn">
profile
</code>
</a>
command.
</p>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 5.0, changes made to the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/#std-label-database-profiler">
database profiler
</a>
<code class="leafygreen-ui-1l06pbn">
level
</code>
,
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
,
<code class="leafygreen-ui-1l06pbn">
sampleRate
</code>
, or
<code class="leafygreen-ui-1l06pbn">
filter
</code>
using the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/profile/#mongodb-dbcommand-dbcmd.profile">
<code class="leafygreen-ui-1l06pbn">
profile
</code>
</a>
command or
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.setProfilingLevel" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</span>
</a>
wrapper method are recorded in the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongod/#std-option-mongod.--logpath">
<code class="leafygreen-ui-1l06pbn">
log file
</code>
.
</a>
</p>
</dd>
</dl>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" 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>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.setProfilingLevel" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</span>
</a>
method has the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.setProfilingLevel(<level>, <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">setProfilingLevel</span>(<<!-- -->level<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->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>
</section>
<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-set-profiling-level-level" target="_self">
<span>
level
</span>
</a>
</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-set-profiling-level-level">
</span>
<p class="leafygreen-ui-1kp3ins">
Configures the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/">
database profiler
</a>
level. The following
profiler levels are available:
</p>
<dl>
<dt>
<code class="leafygreen-ui-1l06pbn">
0
</code>
</dt>
<dd class="css-1ufxuu7">
The profiler is off and does not collect any data.
This is the default profiler level.
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
1
</code>
</dt>
<dd class="css-1ufxuu7">
<p class="leafygreen-ui-1kp3ins">
The profiler collects data for operations that exceed the
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
threshold or match a specified
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When a filter is set:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
and
<code class="leafygreen-ui-1l06pbn">
sampleRate
</code>
options are not used for
profiling.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The profiler only captures operations that match the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
<!-- -->
.
</span>
</a>
</p>
</li>
</ul>
</dd>
<dt>
<code class="leafygreen-ui-1l06pbn">
2
</code>
</dt>
<dd class="css-1ufxuu7">
The profiler collects data for all operations.
</dd>
</dl>
<p class="leafygreen-ui-1kp3ins">
Because profiling is not available on
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.setProfilingLevel" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
</span>
</a>
cannot be used to set the profiling
level to a value other than
<code class="leafygreen-ui-1l06pbn">
0
</code>
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>
</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-set-profiling-level-options" target="_self">
<span>
options
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document or integer
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-set-profiling-level-options">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional. Accepts an integer or an options document. If an integer value is
passed as the
<code class="leafygreen-ui-1l06pbn">
options
</code>
argument instead of a document, the value is
assigned to
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
.
The following options are available:
</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">
</thead>
<tbody>
<tr class="">
<td class="leafygreen-ui-xejatx" role="rowheader">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-set-profiling-level-options-slowms">
</span>
<div class="line-block">
<div class="line">
Default: 100
</div>
<div class="line">
Type: integer
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The slow operation time threshold, in milliseconds. Operations that run
for longer than this threshold are considered
<em>
slow
</em>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Slow operations are logged based on
<code class="leafygreen-ui-1l06pbn">
workingMillis
</code>
, which is the
amount of time that MongoDB spends working on that operation. This means
that factors such as waiting for locks and flow control do not affect
whether an operation exceeds the slow operation threshold.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
is set to
<code class="leafygreen-ui-1l06pbn">
0
</code>
, MongoDB records
<em>
slow
</em>
operations to the diagnostic log at a rate determined by
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpSampleRate">
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
At higher
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
settings, all operations appear in
the diagnostic log regardless of their latency with the following
exception: the logging of slow oplog entry messages by the
secondaries. The secondaries log only the slow oplog
entries; increasing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/parameters/#mongodb-parameter-param.logLevel">
<code class="leafygreen-ui-1l06pbn">
logLevel
</code>
</a>
does not log all
oplog entries.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<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 setting affects both the
diagnostic log and, if enabled, the profiler.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the setting affects
the diagnostic log only and not the profiler because
profiling is not available on
<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">
This argument affects the same setting as the configuration
file option
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpThresholdMs">
<code class="leafygreen-ui-1l06pbn">
slowOpThresholdMs
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-xejatx" role="rowheader">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-set-profiling-level-options-sampleRate">
</span>
<div class="line-block">
<div class="line">
Default: 1.0
</div>
<div class="line">
Type: double
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The fraction of
<em>
slow
</em>
operations that should be profiled or logged.
<code class="leafygreen-ui-1l06pbn">
sampleRate
</code>
accepts values between 0 and 1, inclusive.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<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 setting affects both the
diagnostic log and, if enabled, the profiler.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the setting affects
the diagnostic log only and not the profiler because
profiling is not available on
<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">
This argument affects the same setting as the
configuration option
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/configuration-options/#mongodb-setting-operationProfiling.slowOpSampleRate">
<code class="leafygreen-ui-1l06pbn">
slowOpSampleRate
</code>
.
</a>
</p>
</div>
</div>
</td>
</tr>
<tr class="">
<td class="leafygreen-ui-xejatx" role="rowheader">
<div class="leafygreen-ui-1n4j8xf">
<div>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
</span>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-set-profiling-level-options-filter">
</span>
<p class="leafygreen-ui-1kp3ins">
Type: object
</p>
<p class="leafygreen-ui-1kp3ins">
A filter expression that controls which operations are
profiled and logged. The field in the filter expression
can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/database-profiler/#std-label-profiler">
any field in the profiler output
<!-- -->
.
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
For
<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 setting affects both the
diagnostic log and, if enabled, the profiler.
</p>
<p class="leafygreen-ui-1kp3ins">
For
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/program/mongos/#mongodb-binary-bin.mongos">
<code class="leafygreen-ui-1l06pbn">
mongos
</code>
</a>
instances, the setting affects
the diagnostic log only and not the profiler because
profiling is not available on
<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">
Starting in MongoDB 8.0, you can specify
<code class="leafygreen-ui-1l06pbn">
workingMillis
</code>
as a filter parameter to log operations based on the
amount of time MongoDB spends working on that operation.
</p>
<p class="leafygreen-ui-1kp3ins">
For an example of a filter used to control logged
operations, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-profiler-filter-example" target="_self">
<span>
Set a Filter to Determine Profiled Operations
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
When a profiling
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
</span>
</a>
is set, the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
options do
not affect the diagnostic log or the profiler.
</p>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Returns
<a class="headerlink leafygreen-ui-1kepx47" href="#returns" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="returns">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The method returns a document that contains the
<strong>
previous
</strong>
values of
the settings.
</p>
<div aria-hidden="true">
</div>
<div class="leafygreen-ui-1b75luy" data-lgid="lg-tabs">
<div class="leafygreen-ui-jp7pox" id="tabs-9">
<div aria-label="Tabs to describe usage of mongos/repl-set/standalone" aria-orientation="horizontal" class="leafygreen-ui-m8p1vb lg-ui-tab-list-0000" data-lgid="lg-tabs-tab_list" role="tablist">
<button aria-controls="_tvtiyzbgn" aria-selected="true" class="leafygreen-ui-1l773z1" data-text="" id="_cam4k5alh" name="" role="tab" tabindex="0">
<div class="leafygreen-ui-1nxuzmg">
Standalone
</div>
</button>
<button aria-controls="_t5jot746l" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_h1m52xf7x" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
Replica Set Member
</div>
</button>
<button aria-controls="_hpq7v5iaf" aria-selected="false" class="leafygreen-ui-1ogxb8f" data-text="" id="_tjzyoahes" name="" role="tab" tabindex="-1">
<div class="leafygreen-ui-1nxuzmg">
mongos Instance
</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="_wz3mfn2li" class="" id="_7gulb475z" 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":"{\n \"was\" : 2,\n \"slowms\" : 100,\n \"sampleRate\" : 1,\n \"filter\" : {\n \"$and\" : [\n {\n \"op\" : {\n \"$eq\" : \"query\"\n }\n },\n {\n \"millis\" : {\n \"$gt\" : 20000\n }\n }\n ]\n },\n \"note\" : \"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.\",\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">"was"</span> <!-- -->: <span class="lg-highlight-number">2</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"slowms"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sampleRate"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"filter"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$and"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"op"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$eq"</span> <!-- -->: <span class="lg-highlight-string">"query"</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">"millis"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$gt"</span> <!-- -->: <span class="lg-highlight-number">20000</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">"note"</span> <!-- -->: <span class="lg-highlight-string">"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines."</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>
</div>
</div>
</div>
<div>
<div aria-labelledby="_la2mtkona" class="leafygreen-ui-38lglc" id="_j4c218ei0" 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":"{\n \"was\" : 0,\n \"slowms\" : 100,\n \"sampleRate\" : 1,\n \"filter\" : {\n \"$and\" : [\n {\n \"op\" : {\n \"$eq\" : \"query\"\n }\n },\n {\n \"millis\" : {\n \"$gte\" : 2000\n }\n }\n ]\n },\n \"note\" : \"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.\",\n \"ok\" : 1,\n \"$clusterTime\" : {\n \"clusterTime\" : Timestamp(1572991238, 1),\n \"signature\" : {\n \"hash\" : BinData(0,\"hg6GnlrVhV9MAhwWdeHmHQ4T4qU=\"),\n \"keyId\" : NumberLong(\"6755945537557495811\")\n }\n },\n \"operationTime\" : Timestamp(1572991238, 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">"was"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"slowms"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sampleRate"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"filter"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$and"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"op"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$eq"</span> <!-- -->: <span class="lg-highlight-string">"query"</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">"millis"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$gte"</span> <!-- -->: <span class="lg-highlight-number">2000</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">"note"</span> <!-- -->: <span class="lg-highlight-string">"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines."</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"> <span class="lg-highlight-string">"$clusterTime"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"clusterTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1572991238</span>, <span class="lg-highlight-number">1</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"signature"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hash"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"hg6GnlrVhV9MAhwWdeHmHQ4T4qU="</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"6755945537557495811"</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">"operationTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1572991238</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>
</div>
</div>
</div>
<div>
<div aria-labelledby="_bf3v5tob3" class="leafygreen-ui-38lglc" id="_18vnjomnj" 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":"{\n \"was\" : 0,\n \"slowms\" : 100,\n \"sampleRate\" : 1,\n \"filter\" : {\n \"$and\" : [\n {\n \"op\" : {\n \"$eq\" : \"query\"\n }\n },\n {\n \"millis\" : {\n \"$gte\" : 2000\n }\n }\n ]\n },\n \"note\" : \"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines.\",\n \"ok\" : 1,\n \"operationTime\" : Timestamp(1572991499, 2),\n \"$clusterTime\" : {\n \"clusterTime\" : Timestamp(1572991499, 2),\n \"signature\" : {\n \"hash\" : BinData(0,\"nhCquIxUw7thlrBudXe3PnsnvP0=\"),\n \"keyId\" : NumberLong(\"6755946491040235540\")\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">"was"</span> <!-- -->: <span class="lg-highlight-number">0</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"slowms"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"sampleRate"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"filter"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$and"</span> <!-- -->: <!-- -->[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"op"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$eq"</span> <!-- -->: <span class="lg-highlight-string">"query"</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">"millis"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"$gte"</span> <!-- -->: <span class="lg-highlight-number">2000</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">"note"</span> <!-- -->: <span class="lg-highlight-string">"When a filter expression is set, slowms and sampleRate are not used for profiling and slow-query log lines."</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"> <span class="lg-highlight-string">"operationTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1572991499</span>, <span class="lg-highlight-number">2</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-string">"clusterTime"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">Timestamp</span>(<span class="lg-highlight-number">1572991499</span>, <span class="lg-highlight-number">2</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"signature"</span> <!-- -->: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"hash"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">BinData</span>(<span class="lg-highlight-number">0</span>,<span class="lg-highlight-string">"nhCquIxUw7thlrBudXe3PnsnvP0="</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"keyId"</span> <!-- -->: <span class="lg-highlight-title lg-highlight-class">NumberLong</span>(<span class="lg-highlight-string">"6755946491040235540"</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>
</div>
</div>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Where:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
was
</code>
is the
<strong>
previous
</strong>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
level
</span>
</a>
setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
slowms
</code>
is the
<strong>
previous
</strong>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sampleRate
</code>
is the
<strong>
previous
</strong>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
filter
</code>
is the
<strong>
previous
</strong>
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
</span>
</a>
setting.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
note
</code>
is a string explaining the behavior of
<code class="leafygreen-ui-1l06pbn">
filter
</code>
. This field
only appears in the output when
<code class="leafygreen-ui-1l06pbn">
filter
</code>
is also present.
</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">
The
<code class="leafygreen-ui-1l06pbn">
filter
</code>
and
<code class="leafygreen-ui-1l06pbn">
note
</code>
fields only appear in the output if
they were present in the previous
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
level
</span>
</a>
setting.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To view the current profiling level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getProfilingStatus/#mongodb-method-db.getProfilingStatus">
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
.
</a>
</p>
</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>
<div class="leafygreen-ui-1sjx7ru" role="note">
<h2 class="leafygreen-ui-29m78u">
Warning
</h2>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Profiling can degrade performance and expose unencrypted query data in the
system log. Carefully consider any performance and security implications
before configuring and enabling the profiler on a production deployment.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/tutorial/manage-the-database-profiler/#std-label-database-profiling-overhead">
Profiler Overhead
</a>
for more information on
potential performance degradation.
</p>
</div>
</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">
Enable Profiler and Set Slow Operation Threshold and Sample Rate
<a class="headerlink leafygreen-ui-1kepx47" href="#enable-profiler-and-set-slow-operation-threshold-and-sample-rate" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-profiler-and-set-slow-operation-threshold-and-sample-rate">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example sets for a
<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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
profiling level
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
1
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the slow operation threshold
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
20
</code>
milliseconds, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0.42
</code>
.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.setProfilingLevel(1, { slowms: 20, sampleRate: 0.42 })","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">setProfilingLevel</span>(<span class="lg-highlight-number">1</span>, <!-- -->{ <span class="lg-highlight-attr">slowms</span>: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-attr">sampleRate</span>: <span class="lg-highlight-number">0.42</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
<strong>
previous
</strong>
values for the
settings.
</p>
<p class="leafygreen-ui-1kp3ins">
To view the current profiling level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getProfilingStatus/#mongodb-method-db.getProfilingStatus">
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Disable Profiler and Set Slow Operation Threshold and Sample Rate
<a class="headerlink leafygreen-ui-1kepx47" href="#disable-profiler-and-set-slow-operation-threshold-and-sample-rate" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-profiler-and-set-slow-operation-threshold-and-sample-rate">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example sets for a
<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>
instance:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
profiling level
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the slow operation threshold
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-slowms" target="_self">
<span>
slowms
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
20
</code>
milliseconds, and
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-sampleRate" target="_self">
<span>
sampleRate
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
0.42
</code>
.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.setProfilingLevel(0, { slowms: 20, sampleRate: 0.42 })","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">setProfilingLevel</span>(<span class="lg-highlight-number">0</span>, <!-- -->{ <span class="lg-highlight-attr">slowms</span>: <span class="lg-highlight-number">20</span>, <span class="lg-highlight-attr">sampleRate</span>: <span class="lg-highlight-number">0.42</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
<strong>
previous
</strong>
values for the
settings.
</p>
<p class="leafygreen-ui-1kp3ins">
To view the current profiling level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getProfilingStatus/#mongodb-method-db.getProfilingStatus">
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-profiler-filter-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Set a Filter to Determine Profiled Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#set-a-filter-to-determine-profiled-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="set-a-filter-to-determine-profiled-operations">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following example sets for a
<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>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-level" target="_self">
<span>
profiling level
</span>
</a>
to
<code class="leafygreen-ui-1l06pbn">
1
</code>
,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
a
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-set-profiling-level-options-filter" target="_self">
<span>
filter
</span>
</a>
of
<code class="leafygreen-ui-1l06pbn">
{ op: "query", millis: { $gt: 2000 } }
</code>
, which causes the profiler
to only record
<code class="leafygreen-ui-1l06pbn">
query
</code>
operations that took longer than 2 seconds.
</p>
</li>
</ul>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.setProfilingLevel( 1, { filter: { op: \"query\", millis: { $gt: 2000 } } } )","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">setProfilingLevel</span>( <span class="lg-highlight-number">1</span>, <!-- -->{ <span class="lg-highlight-attr">filter</span>: <!-- -->{ <span class="lg-highlight-attr">op</span>: <span class="lg-highlight-string">"query"</span>, <span class="lg-highlight-attr">millis</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">2000</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
<strong>
previous
</strong>
values for the
settings.
</p>
<p class="leafygreen-ui-1kp3ins">
To view the current profiling level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getProfilingStatus/#mongodb-method-db.getProfilingStatus">
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Unset a Filter
<a class="headerlink leafygreen-ui-1kepx47" href="#unset-a-filter" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="unset-a-filter">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
To clear a profile filter, run
<code class="leafygreen-ui-1l06pbn">
db.setProfilingLevel()
</code>
with the
<code class="leafygreen-ui-1l06pbn">
filter: "unset"
</code>
option.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.setProfilingLevel( 1, { filter: \"unset\" } )","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">setProfilingLevel</span>( <span class="lg-highlight-number">1</span>, <!-- -->{ <span class="lg-highlight-attr">filter</span>: <span class="lg-highlight-string">"unset"</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
<strong>
previous
</strong>
values for the
settings.
</p>
<p class="leafygreen-ui-1kp3ins">
To view the current profiling level, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.getProfilingStatus/#mongodb-method-db.getProfilingStatus">
<code class="leafygreen-ui-1l06pbn">
db.getProfilingStatus()
</code>
.
</a>
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/command/nav-aggregation/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Aggregation Commands
<a class="headerlink leafygreen-ui-1kepx47" href="#aggregation-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="aggregation-commands">
</div>
</a>
</h1>
<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 details on a specific command, including syntax and examples,
click on the link to the command's reference page.
</p>
</div>
</div>
<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>
Name
</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/command/aggregate/#mongodb-dbcommand-dbcmd.aggregate">
<code class="leafygreen-ui-1l06pbn">
aggregate
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation tasks
</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>
using an aggregation pipeline.
</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/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>
Counts the number of documents in a collection or a view.
</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/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>
Displays the distinct values found for a specified key in a collection or a view.
</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/command/mapReduce/#mongodb-dbcommand-dbcmd.mapReduce">
<code class="leafygreen-ui-1l06pbn">
mapReduce
</code>
</a>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Performs
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/map-reduce/#std-label-map-reduce">
map-reduce
</a>
aggregation for large data sets.
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p class="leafygreen-ui-1kp3ins">
For a detailed comparison of the different approaches, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/aggregation-commands-comparison/">
Aggregation Commands Comparison
<!-- -->
.
</a>
</p>
</section>
|
https://www.mongodb.com/docs/manual/reference/method/db.collection.findAndModify/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
db.collection.findAndModify()
<a class="headerlink leafygreen-ui-1kepx47" href="#db.collection.findandmodify--" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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.collection.findandmodify--">
</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="#return-data" target="_self">
<span>
Return Data
</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>
<div class="leafygreen-ui-147elvs">
<p class="leafygreen-ui-1ronz74">
MongoDB with drivers
</p>
<div class="leafygreen-ui-18k5rfm">
<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. To see the equivalent
method in a MongoDB driver, see the corresponding page for your
programming language:
</p>
</div>
<div class="leafygreen-ui-zgrwqu notranslate">
<a class="leafygreen-ui-v22cck" href="https://mongodb.github.io/mongo-csharp-driver/2.29.0/api/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.FindOneAndUpdate.html" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59964)">
<g clip-path="url(#clip1_1351_59964)">
<path d="M25.7709 9.2495C25.7709 8.79827 25.678 8.39408 25.4827 8.04627C25.2874 7.70785 25.0084 7.42586 24.627 7.20025C21.465 5.35781 18.2937 3.51538 15.1317 1.67295C14.2761 1.17474 13.4484 1.19354 12.6021 1.70115C11.3466 2.45316 5.04112 6.10042 3.15321 7.20025C2.3813 7.65142 2 8.34705 2 9.24005C2 12.9531 2 16.6568 2 20.3698C2 20.8117 2.093 21.2064 2.279 21.5449C2.4743 21.8927 2.7626 22.1841 3.15321 22.4191C5.03182 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2761 28.4446 15.1317 27.9463C18.2937 26.1039 21.465 24.2615 24.627 22.4191C25.0177 22.1935 25.306 21.9021 25.5012 21.5449C25.6873 21.2064 25.7803 20.8117 25.7803 20.3698C25.7709 20.3698 25.7709 12.9531 25.7709 9.2495Z" fill="#A179DC">
</path>
<path d="M13.9227 14.7673L2.27905 21.5449C2.47435 21.8927 2.76265 22.1841 3.15326 22.4191C5.03187 23.5189 11.3373 27.1662 12.6021 27.9182C13.4484 28.4258 14.2762 28.4445 15.1317 27.9463C18.2938 26.1039 21.4651 24.2615 24.6271 22.4191C25.0177 22.1935 25.306 21.9021 25.5013 21.5449L13.9227 14.7673Z" fill="#280068">
</path>
<path d="M25.7711 9.24949C25.7711 8.79827 25.6781 8.39408 25.4828 8.04626L13.9229 14.7768L25.4921 21.5543C25.6781 21.2159 25.7711 20.8211 25.7711 20.3793C25.7711 20.3699 25.7711 12.9531 25.7711 9.24949Z" fill="#390091">
</path>
<path d="M20.7771 12.2387V13.5078H22.0325V12.2387H22.6557V13.5078H23.9111V14.1376H22.6557V15.4066H23.9111V16.0364H22.6557V17.3054H22.0325V16.0364H20.7771V17.3054H20.1539V16.0364H18.8984V15.4066H20.1539V14.1376H18.8984V13.5078H20.1539V12.2387H20.7771ZM22.0325 14.1376H20.7771V15.4066H22.0325V14.1376Z" fill="white">
</path>
<path d="M13.9508 5.87482C17.2151 5.87482 20.0702 7.67022 21.6047 10.3399L21.5861 10.3117L17.7452 12.5489C16.9919 11.2517 15.5969 10.3775 14.0066 10.3587H13.9601C11.5328 10.3587 9.56116 12.3515 9.56116 14.805C9.56116 15.604 9.77503 16.3654 10.1377 17.014C10.9004 18.3488 12.3232 19.2512 13.9601 19.2512C15.6062 19.2512 17.0384 18.3394 17.7917 16.9858L17.7731 17.014L21.614 19.2606C20.0981 21.9021 17.2895 23.6975 14.0531 23.7257H13.9508C10.6679 23.7257 7.81274 21.9209 6.28753 19.2418C5.54353 17.9352 5.11572 16.4124 5.11572 14.7956C5.11572 9.87931 9.06825 5.87482 13.9508 5.87482Z" fill="white">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59964">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59964">
<rect fill="white" height="27" transform="translate(2 1.30966)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C#
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://www.mongodb.com/docs/drivers/java/sync/current/fundamentals/crud/compound-operations/#find-and-update" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD">
</path>
<path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD">
</path>
<path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E">
</path>
<path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD">
</path>
<path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD">
</path>
<path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD">
</path>
<path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E">
</path>
<path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD">
</path>
</svg>
<span>
Java Sync
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://mongodb.github.io/node-mongodb-native/6.9/classes/Collection.html#findOneAndUpdate" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 30" width="24" 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(#:R2dttqcmqn9:paint2)">
</path>
</g>
</g>
</g>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R2dttqcmqn9: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=":R2dttqcmqn9: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=":R2dttqcmqn9: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>
<span>
Node.js
</span>
</a>
<a class="leafygreen-ui-v22cck" href="https://pymongo.readthedocs.io/en/stable/api/pymongo/collection.html#pymongo.collection.Collection.find_one_and_update" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 111.6 147" width="24" xmlns="http://www.w3.org/2000/svg">
<lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2httqcmqn9:aa" x1="280.848" x2="389.865" y1="-268.463" y2="-362.257">
<stop offset="0" stop-color="#5a9fd4">
</stop>
<stop offset="1" stop-color="#306998">
</stop>
</lineargradient>
<path d="M55.3 3.2c-4.6 0-9 .4-12.8 1.1-11.3 2-13.4 6.2-13.4 13.9v10.2h26.8v3.4H19c-7.8 0-14.6 4.7-16.8 13.6C-.3 55.6-.4 62 2.2 72.7c1.9 7.9 6.5 13.6 14.2 13.6h9.2V74c0-8.8 7.7-16.7 16.7-16.7h26.8c7.5 0 13.4-6.1 13.4-13.6V18.2c0-7.3-6.1-12.7-13.4-13.9-4.4-.8-9.2-1.1-13.8-1.1zm-14.5 8.2c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1s2.2-5.1 5-5.1z" fill="url(#:R2httqcmqn9:aa)">
</path>
<lineargradient gradienttransform="matrix(.5625 0 0 -.568 -160.323 -146.09)" gradientunits="userSpaceOnUse" id=":R2httqcmqn9:bb" x1="432.011" x2="393.081" y1="-419.025" y2="-363.946">
<stop offset="0" stop-color="#ffd43b">
</stop>
<stop offset="1" stop-color="#ffe873">
</stop>
</lineargradient>
<path d="M86 31.8v11.9c0 9.2-7.8 17-16.8 17H42.5c-7.3 0-13.4 6.3-13.4 13.6v25.5c0 7.3 6.3 11.5 13.4 13.6 8.5 2.5 16.6 2.9 26.8 0 6.8-2 13.4-5.9 13.4-13.6V89.7H55.9v-3.4h40.2c7.8 0 10.7-5.4 13.4-13.6 2.8-8.4 2.7-16.5 0-27.3-1.9-7.8-5.6-13.6-13.4-13.6H86zM71 96.5c2.8 0 5 2.3 5 5.1s-2.3 5.1-5 5.1c-2.8 0-5-2.3-5-5.1-.1-2.8 2.2-5.1 5-5.1z" fill="url(#:R2httqcmqn9:bb)">
</path>
<radialgradient cx="-2274.721" cy="144.526" gradienttransform="matrix(0 -.2399 -1.0547 0 208.637 -414.922)" gradientunits="userSpaceOnUse" id=":R2httqcmqn9:cc" r="29.037">
<stop offset="0" stop-color="#b8b8b8" stop-opacity=".498">
</stop>
<stop offset="1" stop-color="#7f7f7f" stop-opacity="0">
</stop>
</radialgradient>
<path d="M92.1 130.9c0 3.8-16.1 7-35.9 7s-35.9-3.1-35.9-7c0-3.8 16.1-7 35.9-7s35.9 3.1 35.9 7z" fill="url(#:R2httqcmqn9:cc)" opacity=".444">
</path>
</svg>
<span>
PyMongo
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongoc.org/libmongoc/current/mongoc_collection_find_and_modify.html" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59955)">
<g clip-path="url(#clip1_1351_59955)">
<path clip-rule="evenodd" d="M13.118 1.49532C13.5403 1.25103 14.0559 1.25103 14.4783 1.49532C16.5652 2.70389 22.8385 6.34889 24.9193 7.55748C25.3416 7.80172 25.6025 8.25176 25.6025 8.74672C25.6025 11.1703 25.6025 18.4539 25.6025 20.8774C25.6025 21.366 25.3416 21.8224 24.9193 22.0667C22.8385 23.2753 16.5652 26.9203 14.4783 28.1289C14.0559 28.3732 13.5403 28.3732 13.118 28.1289C11.0373 26.9139 4.76398 23.2689 2.68323 22.0603C2.26087 21.816 2 21.366 2 20.871C2 18.4474 2 11.1639 2 8.7403C2 8.25176 2.26087 7.7953 2.68323 7.55106C4.76398 6.34889 11.0373 2.70389 13.118 1.49532Z" fill="#004482" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M2.18634 21.4946C2.01863 21.2632 2 21.051 2 20.7553C2 18.351 2 11.1061 2 8.70176C2 8.21317 2.26087 7.76319 2.67702 7.51889C4.75776 6.31675 11.0062 2.69104 13.0807 1.4889C13.5031 1.24461 14.0683 1.25104 14.4907 1.49533C16.5652 2.69747 22.795 6.29104 24.8696 7.49319C25.0373 7.58963 25.1677 7.70535 25.2795 7.86606L2.18634 21.4946Z" fill="#659AD2" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M13.8011 5.8089C18.6024 5.8089 22.4968 9.83964 22.4968 14.8089C22.4968 19.7782 18.6024 23.8089 13.8011 23.8089C8.99986 23.8089 5.10547 19.7782 5.10547 14.8089C5.10547 9.83964 8.99986 5.8089 13.8011 5.8089ZM13.8011 10.3089C16.1987 10.3089 18.1489 12.3275 18.1489 14.8089C18.1489 17.2903 16.1987 19.3089 13.8011 19.3089C11.4036 19.3089 9.4533 17.2903 9.4533 14.8089C9.4533 12.3275 11.4036 10.3089 13.8011 10.3089Z" fill="white" fill-rule="evenodd">
</path>
<path clip-rule="evenodd" d="M25.2857 7.87247C25.6087 8.18102 25.6025 8.65034 25.6025 9.01673C25.6025 11.4596 25.5839 18.396 25.6087 20.8325C25.6087 21.0896 25.528 21.3532 25.4099 21.5589L13.5466 14.8089L25.2857 7.87247Z" fill="#00599C" fill-rule="evenodd">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59955">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59955">
<rect fill="white" height="27" transform="translate(2 1.30887)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongocxx.org/api/current/classmongocxx_1_1v__noabi_1_1collection.html#ad8a81d6d2b34cf3ece9e21d28f0e1d58" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_1351_59959)">
<g clip-path="url(#clip1_1351_59959)">
<path d="M25.4013 21.5646C25.5872 21.2353 25.7034 20.8745 25.7034 20.5373V9.08012C25.7034 8.75078 25.5872 8.38217 25.4013 8.05283L13.8516 14.8127L25.4013 21.5646Z" fill="#00599C">
</path>
<path d="M14.8738 28.0657L24.6729 22.3411C24.9517 22.1764 25.2151 21.8941 25.401 21.5647L13.8513 14.8127L2.30151 21.5647C2.48743 21.8941 2.74305 22.1764 3.02967 22.3411L12.8288 28.0657C13.3865 28.3951 14.316 28.3951 14.8738 28.0657Z" fill="#004482">
</path>
<path d="M25.4011 8.06086C25.2152 7.73146 24.9596 7.44915 24.673 7.2845L14.8739 1.55983C14.3084 1.23046 13.3866 1.23046 12.8211 1.55983L3.02202 7.2845C2.46429 7.61385 1.99951 8.42158 1.99951 9.08033V20.5375C1.99951 20.8669 2.11571 21.2354 2.30162 21.5647L13.8514 14.8128L25.4011 8.06086Z" fill="#659AD2">
</path>
<path d="M13.8512 22.8115C9.49778 22.8115 5.94995 19.2199 5.94995 14.8127C5.94995 10.4055 9.49778 6.81387 13.8512 6.81387C16.6631 6.81387 19.2813 8.34305 20.6912 10.8133L17.2751 12.813C16.5701 11.5818 15.261 10.8133 13.8512 10.8133C11.6745 10.8133 9.90055 12.6091 9.90055 14.8127C9.90055 17.0163 11.6745 18.8121 13.8512 18.8121C15.261 18.8121 16.5701 18.0436 17.2751 16.8124L20.6912 18.8121C19.2813 21.2745 16.6631 22.8115 13.8512 22.8115Z" fill="white">
</path>
<path d="M21.7524 14.3657H20.8771V13.4796H19.994V14.3657H19.1187V15.2518H19.994V16.1458H20.8771V15.2518H21.7524V14.3657Z" fill="white">
</path>
<path d="M25.0446 14.3657H24.1693V13.4796H23.2862V14.3657H22.4109V15.2518H23.2862V16.1458H24.1693V15.2518H25.0446V14.3657Z" fill="white">
</path>
</g>
</g>
<defs>
<clippath id="clip0_1351_59959">
<rect fill="white" height="28" transform="translate(0 0.809265)" width="28">
</rect>
</clippath>
<clippath id="clip1_1351_59959">
<rect fill="white" height="27" transform="translate(1.99951 1.30878)" width="24">
</rect>
</clippath>
</defs>
</svg>
<span>
C++
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/go/current/fundamentals/crud/compound-operations/#find-and-update" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" id="Layer_1" style="fill:#00ACD7" version="1.1" viewbox="0 0 205.4 76.7" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0">
<path class="st00" d="M15.5 23.2c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h35.7c.4 0 .5.3.3.6l-1.7 2.6c-.2.3-.7.6-1 .6l-36.2-.1zM.4 32.4c-.4 0-.5-.2-.3-.5l2.1-2.7c.2-.3.7-.5 1.1-.5h45.6c.4 0 .6.3.5.6l-.8 2.4c-.1.4-.5.6-.9.6l-47.3.1zM24.6 41.6c-.4 0-.5-.3-.3-.6l1.4-2.5c.2-.3.6-.6 1-.6h20c.4 0 .6.3.6.7l-.2 2.4c0 .4-.4.7-.7.7l-21.8-.1z">
</path>
<g id="CXHf1q_3_">
<path class="st00" d="M128.4 21.4c-6.3 1.6-10.6 2.8-16.8 4.4-1.5.4-1.6.5-2.9-1-1.5-1.7-2.6-2.8-4.7-3.8-6.3-3.1-12.4-2.2-18.1 1.5-6.8 4.4-10.3 10.9-10.2 19 .1 8 5.6 14.6 13.5 15.7 6.8.9 12.5-1.5 17-6.6.9-1.1 1.7-2.3 2.7-3.7H89.6c-2.1 0-2.6-1.3-1.9-3 1.3-3.1 3.7-8.3 5.1-10.9.3-.6 1-1.6 2.5-1.6h36.4c-.2 2.7-.2 5.4-.6 8.1-1.1 7.2-3.8 13.8-8.2 19.6-7.2 9.5-16.6 15.4-28.5 17-9.8 1.3-18.9-.6-26.9-6.6-7.4-5.6-11.6-13-12.7-22.2-1.3-10.9 1.9-20.7 8.5-29.3C70.4 8.7 79.8 2.8 91.3.7c9.4-1.7 18.4-.6 26.5 4.9 5.3 3.5 9.1 8.3 11.6 14.1.6.9.2 1.4-1 1.7z">
</path>
<path class="st00" d="M161.5 76.7c-9.1-.2-17.4-2.8-24.4-8.8-5.9-5.1-9.6-11.6-10.8-19.3-1.8-11.3 1.3-21.3 8.1-30.2 7.3-9.6 16.1-14.6 28-16.7 10.2-1.8 19.8-.8 28.5 5.1 7.9 5.4 12.8 12.7 14.1 22.3 1.7 13.5-2.2 24.5-11.5 33.9-6.6 6.7-14.7 10.9-24 12.8-2.7.5-5.4.6-8 .9zm23.8-40.4c-.1-1.3-.1-2.3-.3-3.3-1.8-9.9-10.9-15.5-20.4-13.3-9.3 2.1-15.3 8-17.5 17.4-1.8 7.8 2 15.7 9.2 18.9 5.5 2.4 11 2.1 16.3-.6 7.9-4.1 12.2-10.5 12.7-19.1z">
</path>
</g>
</svg>
<span>
Go
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoCollection.html#findOneAndUpdate(org.bson.conversions.Bson,org.bson.conversions.Bson)" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 30 41" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M10.0921 30.7949C10.0921 30.7949 8.57608 31.6793 11.166 31.9636C14.2929 32.311 15.9037 32.2794 19.3464 31.6161C19.3464 31.6161 20.2623 32.1846 21.5257 32.6901C13.7876 35.9748 4.02791 32.5005 10.0921 30.7949Z" fill="#0074BD">
</path>
<path d="M9.14539 26.4678C9.14539 26.4678 7.43985 27.7312 10.0298 27.9838C13.3778 28.3312 15.9992 28.3628 20.579 27.4785C20.579 27.4785 21.2107 28.1101 22.1898 28.4576C12.8724 31.2054 2.44949 28.6787 9.14539 26.4678Z" fill="#0074BD">
</path>
<path d="M17.1039 19.1398C18.9989 21.3191 16.5985 23.3089 16.5985 23.3089C16.5985 23.3089 21.431 20.8138 19.2201 17.6869C17.1355 14.7811 15.5563 13.3282 24.1788 8.33789C24.1473 8.33789 10.6607 11.6858 17.1039 19.1398Z" fill="#EA2D2E">
</path>
<path d="M27.3377 33.9845C27.3377 33.9845 28.4431 34.9004 26.1059 35.6269C21.6525 36.985 7.53417 37.3957 3.61769 35.6901C2.19639 35.0899 4.84949 34.2372 5.67069 34.0477C6.52347 33.8582 7.02884 33.8898 7.02884 33.8898C5.44961 32.7843 -3.10981 36.0691 2.67016 36.9851C18.4308 39.5433 31.4121 35.8164 27.3377 33.9845Z" fill="#0074BD">
</path>
<path d="M10.8194 21.983C10.8194 21.983 3.6497 23.6885 8.2926 24.3203C10.2509 24.5729 14.1357 24.5097 17.7995 24.2255C20.7685 23.9728 23.7375 23.4359 23.7375 23.4359C23.7375 23.4359 22.6951 23.8781 21.9372 24.415C14.6411 26.3416 0.585992 25.4257 4.62881 23.4675C8.00839 21.7935 10.8194 21.983 10.8194 21.983Z" fill="#0074BD">
</path>
<path d="M23.6745 29.1846C31.0969 25.3313 27.6542 21.6359 25.2538 22.1413C24.6537 22.2676 24.401 22.3623 24.401 22.3623C24.401 22.3623 24.6221 22.0149 25.0327 21.8886C29.7703 20.2146 33.4025 26.7842 23.5166 29.4057C23.5482 29.3741 23.6429 29.2794 23.6745 29.1846Z" fill="#0074BD">
</path>
<path d="M19.2206 0.25293C19.2206 0.25293 23.3266 4.35891 15.3357 10.6758C8.92404 15.7293 13.8828 18.6351 15.3357 21.9199C11.6087 18.5403 8.86088 15.5714 10.6928 12.792C13.3775 8.74919 20.863 6.79093 19.2206 0.25293Z" fill="#EA2D2E">
</path>
<path d="M11.5455 39.6068C18.6521 40.049 29.5803 39.3541 29.833 35.9746C29.833 35.9746 29.3276 37.238 23.9583 38.2487C17.894 39.3858 10.4085 39.2594 5.95508 38.533C5.95508 38.5646 6.87103 39.3225 11.5455 39.6068Z" fill="#0074BD">
</path>
</svg>
<span>
Java RS
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/fundamentals/crud/compound-operations/#find-and-update" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R35ttqcmqn9:paint0_linear_211_40588)">
</path>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R35ttqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29">
<stop offset="0.00343514" stop-color="#E44857">
</stop>
<stop offset="0.4689" stop-color="#C711E1">
</stop>
<stop offset="1" stop-color="#7F52FF">
</stop>
</lineargradient>
</defs>
</svg>
<span>
Kotlin Coroutine
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/find-one-and-update.html?query=fun%20findOneAndUpdate(clientSession:%20ClientSession,%20filter:%20Bson,%20update:%20Bson,%20options:%20FindOneAndUpdateOptions%20=%20FindOneAndUpdateOptions()):%20T?" target="_self">
<svg class="leafygreen-ui-x3zji3" fill="none" height="24" viewbox="0 0 28 29" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M28 29H0V1H28L14 15L28 29Z" fill="url(#:R39ttqcmqn9:paint0_linear_211_40588)">
</path>
<defs>
<lineargradient gradientunits="userSpaceOnUse" id=":R39ttqcmqn9:paint0_linear_211_40588" x1="28" x2="8.34465e-07" y1="0.999999" y2="29">
<stop offset="0.00343514" stop-color="#E44857">
</stop>
<stop offset="0.4689" stop-color="#C711E1">
</stop>
<stop offset="1" stop-color="#7F52FF">
</stop>
</lineargradient>
</defs>
</svg>
<span>
Kotlin Sync
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/php-library/current/reference/method/MongoDBCollection-findOneAndUpdate/" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 700 301" width="24" x="0" xmlns="http://www.w3.org/2000/svg" y="0">
<defs>
<clippath clippathunits="userSpaceOnUse" id="a">
<path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439">
</path>
</clippath>
<clippath clippathunits="userSpaceOnUse" id="c">
<path d="M0 324h576V0H0v324z">
</path>
</clippath>
<clippath clippathunits="userSpaceOnUse" id="d">
<path d="M0 324h576V0H0v324z">
</path>
</clippath>
<radialgradient cx="0" cy="0" fx="0" fy="0" gradienttransform="matrix(363.05789 0 0 -363.05789 177.52 256.307)" gradientunits="userSpaceOnUse" id="b" r="1" spreadmethod="pad">
<stop offset="0" stop-color="#aeb2d5">
</stop>
<stop offset=".3" stop-color="#aeb2d5">
</stop>
<stop offset=".75" stop-color="#484c89">
</stop>
<stop offset="1" stop-color="#484c89">
</stop>
</radialgradient>
</defs>
<g clip-path="url(#a)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M11.52 162C11.52 81.677 135.307 16.561 288 16.561S564.481 81.677 564.481 162c0 80.322-123.788 145.439-276.481 145.439-152.693 0-276.48-65.117-276.48-145.439" fill="url(#b)">
</path>
</g>
<g clip-path="url(#c)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M288 27.36c146.729 0 265.68 60.28 265.68 134.64 0 74.36-118.951 134.641-265.68 134.641S22.32 236.36 22.32 162.001C22.32 87.64 141.271 27.358 288 27.358" fill="#777bb3">
</path>
</g>
<g clip-path="url(#d)" transform="matrix(1.25 0 0 -1.25 -4.4 394.299)">
<path d="M161.734 145.307c12.065 0 21.072 2.225 26.771 6.61 5.638 4.342 9.532 11.863 11.573 22.354 1.903 9.806 1.178 16.653-2.154 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.28l-10.69-55h15.673zm-63.063-67.75a2.998 2.998 0 00-2.944 3.572l28.328 145.75a3 3 0 002.945 2.428h61.054c19.188 0 33.47-5.21 42.447-15.487 9.025-10.331 11.812-24.772 8.283-42.921-1.436-7.394-3.906-14.261-7.34-20.41-3.44-6.154-7.985-11.85-13.512-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.28-3.93-30.548-3.93h-24.722l-7.06-36.321a3 3 0 00-2.944-2.428h-31.75z">
</path>
<path d="M159.224 197.307h16.808c13.42 0 18.083-2.945 19.667-4.7 2.628-2.914 3.124-9.058 1.435-17.767-1.898-9.75-5.416-16.663-10.458-20.545-5.162-3.974-13.554-5.988-24.941-5.988H149.7l9.523 49zm28.83 35H127a6 6 0 01-5.89-4.855L92.784 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.588 33.895h22.249c12.582 0 23.174 1.372 31.479 4.077 8.54 2.775 16.399 7.48 23.354 13.984 5.752 5.292 10.49 11.232 14.08 17.657 3.59 6.427 6.17 13.594 7.668 21.302 3.715 19.104.697 34.402-8.97 45.466-9.571 10.958-24.613 16.514-44.705 16.514m-45.633-90h19.313c12.8 0 22.336 2.411 28.6 7.234 6.267 4.824 10.493 12.875 12.689 24.157 2.1 10.832 1.144 18.476-2.871 22.93-4.02 4.452-12.06 6.68-24.121 6.68h-21.754l-11.856-61m45.633 84c18.367 0 31.766-4.82 40.188-14.462 8.42-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.621-3.782-29.621-3.782h-27.196l-7.531-38.75h-31.75L127 226.307h61.055" fill="#fff">
</path>
<path d="M311.583 116.307c-.896 0-1.745.4-2.314 1.092a2.994 2.994 0 00-.631 2.48l12.531 64.489c1.192 6.133.898 10.535-.827 12.395-1.056 1.137-4.228 3.044-13.607 3.044h-22.702l-15.755-81.072a3 3 0 00-2.945-2.428h-31.5a2.998 2.998 0 00-2.945 3.572l28.328 145.75a3 3 0 002.945 2.428h31.5a3 3 0 002.945-3.572l-6.836-35.178h24.422c18.605 0 31.221-3.28 38.569-10.028 7.49-6.884 9.827-17.891 6.947-32.72l-13.18-67.824a3 3 0 00-2.945-2.428h-32z">
</path>
<path d="M293.661 271.057h-31.5a6 6 0 01-5.89-4.855l-28.328-145.75a5.998 5.998 0 015.89-7.145h31.5a6 6 0 015.89 4.855l15.283 78.645h20.23c9.362 0 11.327-2 11.406-2.086.568-.61 1.315-3.44.082-9.78l-12.53-64.49a5.998 5.998 0 015.89-7.144h32a6 6 0 015.89 4.855l13.178 67.825c3.093 15.921.447 27.864-7.86 35.5-7.929 7.281-21.209 10.82-40.6 10.82h-20.784l6.143 31.605a6.001 6.001 0 01-5.89 7.145m0-6l-7.53-38.75h28.061c17.657 0 29.836-3.082 36.54-9.238 6.702-6.16 8.71-16.14 6.031-29.938l-13.18-67.824h-32l12.531 64.488c1.426 7.336.902 12.34-1.574 15.008-2.477 2.668-7.746 4.004-15.805 4.004H281.56l-16.226-83.5h-31.5l28.328 145.75h31.5" fill="#fff">
</path>
<path d="M409.55 145.307c12.065 0 21.072 2.225 26.77 6.61 5.639 4.34 9.533 11.862 11.575 22.354 1.903 9.806 1.178 16.653-2.155 20.348-3.407 3.774-10.773 5.688-21.893 5.688h-19.281l-10.69-55h15.674zm-63.062-67.75a2.999 2.999 0 00-2.945 3.572l28.328 145.75a3.002 3.002 0 002.946 2.428h61.053c19.189 0 33.47-5.21 42.448-15.487 9.025-10.33 11.81-24.771 8.283-42.921-1.438-7.394-3.907-14.261-7.342-20.41-3.44-6.154-7.984-11.85-13.511-16.93-6.616-6.191-14.104-10.681-22.236-13.323-8.003-2.607-18.281-3.93-30.548-3.93H388.24l-7.057-36.321a3.001 3.001 0 00-2.946-2.428h-31.75z">
</path>
<path d="M407.04 197.307h16.807c13.421 0 18.083-2.945 19.667-4.7 2.63-2.914 3.125-9.058 1.435-17.766-1.898-9.75-5.417-16.664-10.458-20.546-5.162-3.974-13.554-5.988-24.94-5.988h-12.034l9.522 49zm28.83 35h-61.054a6 6 0 01-5.889-4.855L340.6 81.702a6 6 0 015.889-7.144h31.75a6 6 0 015.89 4.854l6.587 33.895h22.25c12.581 0 23.173 1.372 31.478 4.077 8.541 2.775 16.401 7.481 23.356 13.986 5.752 5.291 10.488 11.23 14.078 17.655 3.591 6.427 6.171 13.594 7.668 21.302 3.715 19.105.697 34.403-8.969 45.467-9.572 10.957-24.613 16.513-44.706 16.513m-45.632-90h19.312c12.801 0 22.336 2.411 28.601 7.234 6.267 4.824 10.492 12.875 12.688 24.157 2.102 10.832 1.145 18.476-2.87 22.93-4.02 4.452-12.06 6.68-24.122 6.68h-21.754l-11.855-61m45.632 84c18.367 0 31.766-4.82 40.188-14.462 8.422-9.64 10.957-23.098 7.597-40.375-1.383-7.117-3.722-13.624-7.015-19.519-3.297-5.899-7.602-11.293-12.922-16.184-6.34-5.933-13.383-10.16-21.133-12.679-7.75-2.525-17.62-3.782-29.62-3.782h-27.197l-7.53-38.75h-31.75l28.328 145.75h61.054" fill="#fff">
</path>
</g>
</svg>
<span>
PHP
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.rubydoc.info/github/mongoid/mongoid/Mongoid/Contextual/Mongo:find_one_and_update" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" preserveaspectratio="xMidYMid" viewbox="0 0 300 240" width="24" xmlns="http://www.w3.org/2000/svg">
<defs>
<lineargradient id=":R3httqcmqn9:a" x1="84.75%" x2="58.254%" y1="111.399%" y2="64.584%">
<stop offset="0%" stop-color="#FB7655">
</stop>
<stop offset="0%" stop-color="#FB7655">
</stop>
<stop offset="41%" stop-color="#E42B1E">
</stop>
<stop offset="99%" stop-color="#900">
</stop>
<stop offset="100%" stop-color="#900">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:b" x1="116.651%" x2="1.746%" y1="60.89%" y2="19.288%">
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="99%" stop-color="#911209">
</stop>
<stop offset="100%" stop-color="#911209">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:c" x1="75.774%" x2="38.978%" y1="219.327%" y2="7.829%">
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="0%" stop-color="#871101">
</stop>
<stop offset="99%" stop-color="#911209">
</stop>
<stop offset="100%" stop-color="#911209">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:d" x1="50.012%" x2="66.483%" y1="7.234%" y2="79.135%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="23%" stop-color="#E57252">
</stop>
<stop offset="46%" stop-color="#DE3B20">
</stop>
<stop offset="99%" stop-color="#A60003">
</stop>
<stop offset="100%" stop-color="#A60003">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:e" x1="46.174%" x2="49.932%" y1="16.348%" y2="83.047%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="23%" stop-color="#E4714E">
</stop>
<stop offset="56%" stop-color="#BE1A0D">
</stop>
<stop offset="99%" stop-color="#A80D00">
</stop>
<stop offset="100%" stop-color="#A80D00">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:f" x1="36.965%" x2="49.528%" y1="15.594%" y2="92.478%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="18%" stop-color="#E46342">
</stop>
<stop offset="40%" stop-color="#C82410">
</stop>
<stop offset="99%" stop-color="#A80D00">
</stop>
<stop offset="100%" stop-color="#A80D00">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:g" x1="13.609%" x2="85.764%" y1="58.346%" y2="-46.717%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="54%" stop-color="#C81F11">
</stop>
<stop offset="99%" stop-color="#BF0905">
</stop>
<stop offset="100%" stop-color="#BF0905">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:h" x1="27.624%" x2="50.745%" y1="21.135%" y2="79.056%">
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="0%" stop-color="#FFF">
</stop>
<stop offset="31%" stop-color="#DE4024">
</stop>
<stop offset="99%" stop-color="#BF190B">
</stop>
<stop offset="100%" stop-color="#BF190B">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:i" x1="-20.667%" x2="104.242%" y1="122.282%" y2="-6.342%">
<stop offset="0%" stop-color="#BD0012">
</stop>
<stop offset="0%" stop-color="#BD0012">
</stop>
<stop offset="7%" stop-color="#FFF">
</stop>
<stop offset="17%" stop-color="#FFF">
</stop>
<stop offset="27%" stop-color="#C82F1C">
</stop>
<stop offset="33%" stop-color="#820C01">
</stop>
<stop offset="46%" stop-color="#A31601">
</stop>
<stop offset="72%" stop-color="#B31301">
</stop>
<stop offset="99%" stop-color="#E82609">
</stop>
<stop offset="100%" stop-color="#E82609">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:j" x1="58.792%" x2="11.964%" y1="65.205%" y2="50.128%">
<stop offset="0%" stop-color="#8C0C01">
</stop>
<stop offset="0%" stop-color="#8C0C01">
</stop>
<stop offset="54%" stop-color="#990C00">
</stop>
<stop offset="99%" stop-color="#A80D0E">
</stop>
<stop offset="100%" stop-color="#A80D0E">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:k" x1="79.319%" x2="23.088%" y1="62.754%" y2="17.888%">
<stop offset="0%" stop-color="#7E110B">
</stop>
<stop offset="0%" stop-color="#7E110B">
</stop>
<stop offset="99%" stop-color="#9E0C00">
</stop>
<stop offset="100%" stop-color="#9E0C00">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:l" x1="92.88%" x2="59.841%" y1="74.122%" y2="39.704%">
<stop offset="0%" stop-color="#79130D">
</stop>
<stop offset="0%" stop-color="#79130D">
</stop>
<stop offset="99%" stop-color="#9E120B">
</stop>
<stop offset="100%" stop-color="#9E120B">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:o" x1="56.57%" x2="3.105%" y1="101.717%" y2="11.993%">
<stop offset="0%" stop-color="#8B2114">
</stop>
<stop offset="0%" stop-color="#8B2114">
</stop>
<stop offset="43%" stop-color="#9E100A">
</stop>
<stop offset="99%" stop-color="#B3100C">
</stop>
<stop offset="100%" stop-color="#B3100C">
</stop>
</lineargradient>
<lineargradient id=":R3httqcmqn9:p" x1="30.87%" x2="92.471%" y1="35.599%" y2="100.694%">
<stop offset="0%" stop-color="#B31000">
</stop>
<stop offset="0%" stop-color="#B31000">
</stop>
<stop offset="44%" stop-color="#910F08">
</stop>
<stop offset="99%" stop-color="#791C12">
</stop>
<stop offset="100%" stop-color="#791C12">
</stop>
</lineargradient>
<radialgradient cx="32.001%" cy="40.21%" fx="32.001%" fy="40.21%" id=":R3httqcmqn9:m" r="69.573%">
<stop offset="0%" stop-color="#A80D00">
</stop>
<stop offset="0%" stop-color="#A80D00">
</stop>
<stop offset="99%" stop-color="#7E0E08">
</stop>
<stop offset="100%" stop-color="#7E0E08">
</stop>
</radialgradient>
<radialgradient cx="13.549%" cy="40.86%" fx="13.549%" fy="40.86%" id=":R3httqcmqn9:n" r="88.386%">
<stop offset="0%" stop-color="#A30C00">
</stop>
<stop offset="0%" stop-color="#A30C00">
</stop>
<stop offset="99%" stop-color="#800E08">
</stop>
<stop offset="100%" stop-color="#800E08">
</stop>
</radialgradient>
</defs>
<path d="M197.467 167.764l-145.52 86.41 188.422-12.787L254.88 51.393l-57.414 116.37z" fill="url(#:R3httqcmqn9:a)">
</path>
<path d="M240.677 241.257L224.482 129.48l-44.113 58.25 60.308 53.528z" fill="url(#:R3httqcmqn9:b)">
</path>
<path d="M240.896 241.257l-118.646-9.313-69.674 21.986 188.32-12.673z" fill="url(#:R3httqcmqn9:c)">
</path>
<path d="M52.744 253.955l29.64-97.1L17.16 170.8l35.583 83.154z" fill="url(#:R3httqcmqn9:d)">
</path>
<path d="M180.358 188.05L153.085 81.226l-78.047 73.16 105.32 33.666z" fill="url(#:R3httqcmqn9:e)">
</path>
<path d="M248.693 82.73l-73.777-60.256-20.544 66.418 94.321-6.162z" fill="url(#:R3httqcmqn9:f)">
</path>
<path d="M214.191.99L170.8 24.97 143.424.669l70.767.322z" fill="url(#:R3httqcmqn9:g)">
</path>
<path d="M0 203.372l18.177-33.151-14.704-39.494L0 203.372z" fill="url(#:R3httqcmqn9:h)">
</path>
<path d="M2.496 129.48l14.794 41.963 64.283-14.422 73.39-68.207 20.712-65.787L143.063 0 87.618 20.75c-17.469 16.248-51.366 48.396-52.588 49-1.21.618-22.384 40.639-32.534 59.73z" fill="#FFF">
</path>
<path d="M54.442 54.094c37.86-37.538 86.667-59.716 105.397-40.818 18.72 18.898-1.132 64.823-38.992 102.349-37.86 37.525-86.062 60.925-104.78 42.027-18.73-18.885.515-66.032 38.375-103.558z" fill="url(#:R3httqcmqn9:i)">
</path>
<path d="M52.744 253.916l29.408-97.409 97.665 31.376c-35.312 33.113-74.587 61.106-127.073 66.033z" fill="url(#:R3httqcmqn9:j)">
</path>
<path d="M155.092 88.622l25.073 99.313c29.498-31.016 55.972-64.36 68.938-105.603l-94.01 6.29z" fill="url(#:R3httqcmqn9:k)">
</path>
<path d="M248.847 82.833c10.035-30.282 12.35-73.725-34.966-81.791l-38.825 21.445 73.791 60.346z" fill="url(#:R3httqcmqn9:l)">
</path>
<path d="M0 202.935c1.39 49.979 37.448 50.724 52.808 51.162l-35.48-82.86L0 202.935z" fill="#9E1209">
</path>
<path d="M155.232 88.777c22.667 13.932 68.35 41.912 69.276 42.426 1.44.81 19.695-30.784 23.838-48.64l-93.114 6.214z" fill="url(#:R3httqcmqn9:m)">
</path>
<path d="M82.113 156.507l39.313 75.848c23.246-12.607 41.45-27.967 58.121-44.42l-97.434-31.428z" fill="url(#:R3httqcmqn9:n)">
</path>
<path d="M17.174 171.34l-5.57 66.328c10.51 14.357 24.97 15.605 40.136 14.486-10.973-27.311-32.894-81.92-34.566-80.814z" fill="url(#:R3httqcmqn9:o)">
</path>
<path d="M174.826 22.654l78.1 10.96c-4.169-17.662-16.969-29.06-38.787-32.623l-39.313 21.663z" fill="url(#:R3httqcmqn9:p)">
</path>
</svg>
<span>
Mongoid
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://www.mongodb.com/docs/drivers/rust/current/fundamentals/crud/compound-operations/#find-and-update-a-document" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 30 30" width="24" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_5454_14623)">
<path d="M15.2561 3.08398C8.56014 3.08398 3.11035 8.53634 3.11035 15.2297C3.11035 21.9231 8.56271 27.3755 15.2561 27.3755C21.9495 27.3755 27.4019 21.9231 27.4019 15.2297C27.4019 8.53634 21.9495 3.08398 15.2561 3.08398ZM15.2381 4.16315C15.4458 4.16853 15.6432 4.25509 15.7881 4.40437C15.9331 4.55365 16.0142 4.75384 16.0141 4.96225C16.0141 5.17418 15.9299 5.37744 15.7801 5.5273C15.6302 5.67715 15.4269 5.76134 15.215 5.76134C15.0031 5.76134 14.7998 5.67715 14.65 5.5273C14.5001 5.37744 14.4159 5.17418 14.4159 4.96225C14.4159 4.85533 14.4373 4.7495 14.4789 4.65101C14.5205 4.55252 14.5814 4.46338 14.6581 4.38887C14.7347 4.31435 14.8256 4.25598 14.9252 4.21721C15.0249 4.17844 15.1313 4.16006 15.2381 4.16315ZM17.0676 5.47871C18.4704 5.74146 19.7992 6.30644 20.9617 7.13439C22.1242 7.96235 23.0926 9.03345 23.7995 10.2733L22.8565 12.4008C22.6947 12.7682 22.8617 13.1999 23.2265 13.3643L25.0406 14.1686C25.0968 14.7356 25.1037 15.3065 25.0611 15.8747H24.0513C23.9511 15.8747 23.91 15.9415 23.91 16.0391V16.5016C23.91 17.5911 23.2959 17.83 22.7563 17.8891C22.2424 17.9482 21.6746 17.6733 21.6026 17.3598C21.2994 15.6563 20.7958 15.294 19.9993 14.6645C20.9885 14.0375 22.0163 13.11 22.0163 11.8715C22.0163 10.5328 21.099 9.69002 20.4747 9.27634C19.5959 8.69822 18.6247 8.5826 18.3626 8.5826H7.93063C9.37312 6.97114 11.3066 5.88021 13.4318 5.47871L14.6626 6.76857C14.9401 7.05891 15.4 7.07176 15.6903 6.79169L17.0676 5.47871ZM5.71063 11.3936C5.91853 11.3996 6.11589 11.4864 6.26079 11.6356C6.40568 11.7849 6.48669 11.9847 6.4866 12.1927C6.4866 12.4046 6.40241 12.6079 6.25255 12.7577C6.10269 12.9076 5.89944 12.9918 5.6875 12.9918C5.47557 12.9918 5.27232 12.9076 5.12246 12.7577C4.9726 12.6079 4.88841 12.4046 4.88841 12.1927C4.88836 12.0858 4.90977 11.9799 4.95137 11.8814C4.99297 11.7829 5.0539 11.6938 5.13057 11.6193C5.20724 11.5448 5.29809 11.4864 5.39772 11.4476C5.49736 11.4089 5.60376 11.3905 5.71063 11.3936ZM24.7631 11.4295C24.971 11.4356 25.1683 11.5224 25.3132 11.6716C25.4581 11.8208 25.5391 12.0206 25.539 12.2286C25.539 12.4406 25.4548 12.6438 25.305 12.7937C25.1551 12.9435 24.9519 13.0277 24.7399 13.0277C24.528 13.0277 24.3247 12.9435 24.1749 12.7937C24.025 12.6438 23.9408 12.4406 23.9408 12.2286C23.9408 12.1217 23.9622 12.0159 24.0038 11.9174C24.0454 11.8189 24.1063 11.7298 24.183 11.6553C24.2597 11.5807 24.3505 11.5224 24.4502 11.4836C24.5498 11.4448 24.6562 11.4264 24.7631 11.4295ZM7.21632 11.558H8.60896V17.8377H5.79799C5.45083 16.6186 5.34264 15.3439 5.47938 14.0838L7.20091 13.3181C7.56834 13.1536 7.73535 12.7245 7.57091 12.3571L7.21632 11.558ZM13.0284 11.6248H16.3456C16.5177 11.6248 17.5558 11.8227 17.5558 12.6012C17.5558 13.2461 16.7592 13.4774 16.104 13.4774H13.0258L13.0284 11.6248ZM13.0284 16.1368H15.5696C15.8008 16.1368 16.8106 16.2036 17.1318 17.4934C17.232 17.8891 17.4556 19.179 17.6072 19.5927C17.7588 20.0552 18.3729 20.9802 19.0281 20.9802H23.1751C22.8972 21.3524 22.5933 21.7044 22.2656 22.0336L20.5774 21.6713C20.1843 21.5866 19.7963 21.8384 19.7115 22.2315L19.3107 24.102C18.0217 24.6859 16.622 24.9848 15.2069 24.9781C13.7919 24.9714 12.395 24.6595 11.1116 24.0635L10.7108 22.1929C10.626 21.7998 10.2406 21.548 9.84743 21.6328L8.19528 21.9874C7.88869 21.6711 7.6037 21.3346 7.34223 20.9802H15.3769C15.4668 20.9802 15.5285 20.9647 15.5285 20.88V18.0381C15.5285 17.9559 15.4668 17.9379 15.3769 17.9379H13.0258L13.0284 16.1368ZM9.3207 22.6452C9.5286 22.6512 9.72596 22.738 9.87085 22.8872C10.0157 23.0364 10.0968 23.2363 10.0967 23.4443C10.0967 23.6562 10.0125 23.8594 9.86262 24.0093C9.71276 24.1592 9.50951 24.2434 9.29757 24.2434C9.08564 24.2434 8.88239 24.1592 8.73253 24.0093C8.58267 23.8594 8.49848 23.6562 8.49848 23.4443C8.49843 23.3373 8.51984 23.2315 8.56144 23.133C8.60303 23.0345 8.66397 22.9454 8.74064 22.8709C8.81731 22.7964 8.90815 22.738 9.00779 22.6992C9.10743 22.6605 9.21383 22.6421 9.3207 22.6452ZM21.153 22.6811C21.3609 22.6872 21.5583 22.774 21.7031 22.9232C21.848 23.0724 21.929 23.2722 21.929 23.4802C21.929 23.6922 21.8448 23.8954 21.6949 24.0453C21.5451 24.1951 21.3418 24.2793 21.1299 24.2793C20.9179 24.2793 20.7147 24.1951 20.5648 24.0453C20.415 23.8954 20.3308 23.6922 20.3308 23.4802C20.3307 23.3733 20.3521 23.2675 20.3937 23.169C20.4353 23.0705 20.4963 22.9814 20.5729 22.9068C20.6496 22.8323 20.7404 22.774 20.8401 22.7352C20.9397 22.6964 21.0461 22.678 21.153 22.6811Z" fill="black">
</path>
<path clip-rule="evenodd" d="M26.7232 15.2304C26.7232 18.2717 25.515 21.1885 23.3645 23.3391C21.2139 25.4896 18.2971 26.6978 15.2558 26.6978C12.2144 26.6978 9.29761 25.4896 7.14705 23.3391C4.99649 21.1885 3.78832 18.2717 3.78832 15.2304C3.78832 12.189 4.99649 9.27222 7.14705 7.12166C9.29761 4.9711 12.2144 3.76293 15.2558 3.76293C18.2971 3.76293 21.2139 4.9711 23.3645 7.12166C25.515 9.27222 26.7232 12.189 26.7232 15.2304ZM26.5073 14.1229L28.2957 15.2304L26.5073 16.3378L28.0439 17.7741L26.0757 18.5115L27.3039 20.2202L25.2252 20.5594L26.0988 22.4762L23.9944 22.4017L24.4775 24.4521L22.4271 23.969L22.5016 26.0734L20.5848 25.1998L20.2456 27.2785L18.5369 26.0503L17.7995 28.0185L16.3632 26.482L15.2558 28.2703L14.1483 26.482L12.712 28.0185L11.9746 26.0503L10.2659 27.2785L9.92672 25.1998L8.00992 26.0734L8.08443 23.969L6.03401 24.4521L6.51707 22.4017L4.4127 22.4762L5.28631 20.5594L3.20763 20.2202L4.43582 18.5115L2.46763 17.7741L4.00415 16.3378L2.21582 15.2304L4.00415 14.1229L2.46763 12.6866L4.43582 11.9492L3.20763 10.2405L5.28631 9.90133L4.4127 7.98453L6.51707 8.05904L6.03401 6.00862L8.08443 6.49168L8.00992 4.3873L9.92672 5.26092L10.2659 3.18223L11.9746 4.41043L12.712 2.44224L14.1483 3.97876L15.2558 2.19043L16.3632 3.97876L17.7995 2.44224L18.5369 4.41043L20.2456 3.18223L20.5848 5.26092L22.5016 4.3873L22.4271 6.49168L24.4775 6.00862L23.9944 8.05904L26.0988 7.98453L25.2252 9.90133L27.3039 10.2405L26.0757 11.9492L28.0439 12.6866L26.5073 14.1229Z" fill="black" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round">
</path>
</g>
<defs>
<clippath id="clip0_5454_14623">
<rect fill="black" height="30" width="30">
</rect>
</clippath>
</defs>
</svg>
<span>
Rust
</span>
</a>
<a class="leafygreen-ui-18cpm0b" href="https://mongodb.github.io/mongo-java-driver/5.2/apidocs/mongo-scala-driver/org/mongodb/scala/MongoCollection.html#findOneAndUpdate(clientSession:org.mongodb.scala.ClientSession,filter:org.mongodb.scala.bson.conversions.Bson,update:Seq[org.mongodb.scala.bson.conversions.Bson],options:org.mongodb.scala.model.FindOneAndUpdateOptions):org.mongodb.scala.SingleObservable[TResult]" target="_self">
<svg class="leafygreen-ui-x3zji3" height="24" viewbox="0 0 70 70" width="24" xmlns="http://www.w3.org/2000/svg">
<defs>
<lineargradient id=":R3pttqcmqn9:aaa" x1=".006%" x2="96.837%" y1="49.998%" y2="49.998%">
<stop offset="0%" stop-color="#CD413F">
</stop>
<stop offset="75.091%" stop-color="#CD4543">
</stop>
<stop offset="100%" stop-color="#D04543">
</stop>
</lineargradient>
</defs>
<g fill="none" fill-rule="nonzero">
<path d="M13 39v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 36.745 13 38.157 13 39M13 20v5c0 .843 17.73 2.255 29.28 5 5.582-1.327 9.72-2.966 9.72-5v-5c0-2.034-4.138-3.673-9.72-5C30.73 17.745 13 19.157 13 20" fill="#731818">
</path>
<g fill="url(#:R3pttqcmqn9:aaa)" transform="translate(13)">
<path d="M0 29.53v14.766c0-1.232 39-3.692 39-9.844V19.686c0 6.152-39 8.612-39 9.844M0 9.843V24.61c0-1.231 39-3.691 39-9.843V0C39 6.152 0 8.612 0 9.843M0 49.216v14.766c0-1.231 39-3.691 39-9.843V39.373c0 6.151-39 8.612-39 9.843">
</path>
</g>
</g>
</svg>
<span>
Scala
</span>
</a>
</div>
<button class="leafygreen-ui-ki2t97">
Show all
<svg aria-label="Chevron Down Icon" class="" fill="none" height="16" role="img" viewbox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg">
<path clip-rule="evenodd" d="M1.636 5.364a1 1 0 0 0 0 1.414l4.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 8.899 3.757 4.657a1 1 0 0 0-1.414 0l-.707.707Z" fill="currentColor" fill-rule="evenodd">
</path>
</svg>
</button>
</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.collection.findAndModify(document)
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#mongodb-method-db.collection.findAndModify" 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.collection.findAndModify">
</div>
</a>
</dt>
<dd>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Deprecated mongosh Method
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
Use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndDelete/#mongodb-method-db.collection.findOneAndDelete">
<code class="leafygreen-ui-1l06pbn">
findOneAndDelete()
</code>
</a>
, or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndReplace/#mongodb-method-db.collection.findOneAndReplace">
<code class="leafygreen-ui-1l06pbn">
findOneAndReplace()
</code>
</a>
instead.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Updates and returns a single document. By default, the returned
document does not include the modifications made on the update. To
return the document with the modifications made on the update, use
the
<code class="leafygreen-ui-1l06pbn">
new
</code>
option.
</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-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>
<div>
<p>
<em>
Changed
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
method has the following
form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.collection.findAndModify({\n query: <document>,\n sort: <document>,\n remove: <boolean>,\n update: <document>,\n new: <boolean>,\n fields: <document>,\n upsert: <boolean>,\n bypassDocumentValidation: <boolean>,\n writeConcern: <document>,\n maxTimeMS: <integer>,\n collation: <document>,\n arrayFilters: [ <filterdocument1>, ... ],\n let: <document> // Added in MongoDB 5.0\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.collection.findAndModify({</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> query: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sort: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> remove: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> update: <document or aggregation pipeline>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> new: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> fields: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> upsert: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> bypassDocumentValidation: <boolean>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> writeConcern: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> maxTimeMS: <integer>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> collation: <document>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> arrayFilters: [ <filterdocument1>, ... ],</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> let: <document> // Added in MongoDB 5.0</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-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
method takes a document
parameter with the following embedded document 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>
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="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<code class="leafygreen-ui-1l06pbn">
query
</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 selection criteria for the modification. The
<code class="leafygreen-ui-1l06pbn">
query
</code>
field
employs the same
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/#std-label-query-selectors">
query selectors
</a>
as used in
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. Although the query may
match multiple documents,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
<strong>
will only select one document to modify
</strong>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If unspecified, defaults to an empty document.
</p>
<p class="leafygreen-ui-1kp3ins">
If the query argument is not a document, the operation errors.
</p>
</div>
</div>
</td>
</tr>
<tr class="leafygreen-ui-15dvrnp">
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-findandmodify-method-consistent-sorting">
</span>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
sort
</code>
</p>
</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. Determines which document the operation updates if the query
selects multiple documents.
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
updates
the first document in the sort order specified by this argument.
</p>
<p class="leafygreen-ui-1kp3ins">
If the sort argument is not a document, the operation errors.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB does not store documents in a collection in a particular order.
When sorting on a field which contains duplicate values, documents
containing those values may be returned in any order.
</p>
<p class="leafygreen-ui-1kp3ins">
If consistent sort order is desired, include at least one field in your
sort that contains unique values. The easiest way to guarantee this is
to include the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in your sort query.
</p>
<p class="leafygreen-ui-1kp3ins">
See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/cursor.sort/#std-label-sort-cursor-consistent-sorting">
Sort Consistency
</a>
for more information.
</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">
remove
</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>
Must specify either the
<code class="leafygreen-ui-1l06pbn">
remove
</code>
or the
<code class="leafygreen-ui-1l06pbn">
update
</code>
field. Removes
the document specified in the
<code class="leafygreen-ui-1l06pbn">
query
</code>
field. Set this to
<code class="leafygreen-ui-1l06pbn">
true
</code>
to remove the selected document . The default 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">
update
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
document or array
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Must specify either the
<code class="leafygreen-ui-1l06pbn">
remove
</code>
or the
<code class="leafygreen-ui-1l06pbn">
update
</code>
field. Performs
an update of the selected document.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If passed a document with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/#std-label-update-operators">
update operator expressions
</a>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
performs the specified
modification.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If passed a replacement document
<code class="leafygreen-ui-1l06pbn">
{ <field1>: <value1>, ...}
</code>
,
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
performs a replacement.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If passed an
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/aggregation-pipeline/#std-label-aggregation-pipeline">
aggregation pipeline
</a>
<code class="leafygreen-ui-1l06pbn">
[ <stage1>, <stage2>, ... ]
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
updates the document per
the pipeline. The pipeline can consist of the following 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>
</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">
new
</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. When
<code class="leafygreen-ui-1l06pbn">
true
</code>
, returns the updated document rather than the original.
The default 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">
fields
</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 subset of fields to return. The
<code class="leafygreen-ui-1l06pbn">
fields
</code>
document specifies
an inclusion of a field with
<code class="leafygreen-ui-1l06pbn">
1
</code>
, as in:
<code class="leafygreen-ui-1l06pbn">
fields: { <field1>: 1,
<field2>: 1, ... }
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
fields
</code>
argument is not a document, the operation errors.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information on projection, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-fields-projection" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
fields
</code>
Projection
<!-- -->
.
</span>
</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">
upsert
</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. Used in conjunction with the
<code class="leafygreen-ui-1l06pbn">
update
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
When
<code class="leafygreen-ui-1l06pbn">
true
</code>
,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Creates a new document if no documents match the
<code class="leafygreen-ui-1l06pbn">
query
</code>
.
For more details see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.update/#std-label-upsert-behavior">
upsert behavior
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Updates a single document that matches the
<code class="leafygreen-ui-1l06pbn">
query
</code>
.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To avoid multiple
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-upsert">
upserts
</a>
, ensure that the
<code class="leafygreen-ui-1l06pbn">
query
</code>
field(s) are
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
uniquely indexed
</a>
. See
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-upsert-and-unique-index" target="_self">
<span>
Upsert with Unique Index
</span>
</a>
for an example.
</p>
<p class="leafygreen-ui-1kp3ins">
Defaults to
<code class="leafygreen-ui-1l06pbn">
false
</code>
, which does
<em>
not
</em>
insert a new document when no
match is found.
</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>
Optional. Enables
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
to bypass document validation
during the operation. This lets you update documents that do not
meet the validation requirements.
</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 expressing the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/write-concern/#std-label-write-concern">
write concern
</a>
.
Omit to use the default write concern.
</p>
<p class="leafygreen-ui-1kp3ins">
Do not explicitly set the write concern for the operation if run in
a transaction. To use write concern with transactions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern">
Transactions and Write Concern
<!-- -->
.
</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">
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.
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a time limit in milliseconds.
If you do not specify a value for
<code class="leafygreen-ui-1l06pbn">
maxTimeMS
</code>
, 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">
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-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">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">
arrayFilters
</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>
<p class="leafygreen-ui-1kp3ins">
Optional. An array of filter documents that determine which array elements to
modify for an update operation on an array field.
</p>
<p class="leafygreen-ui-1kp3ins">
In the update document, use the
<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>
filtered
positional operator to define an identifier, which you then reference
in the array filter documents. You cannot have an array filter
document for an identifier if the identifier is not included in the
update document.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
<identifier>
</code>
must begin with a lowercase letter and
contain only alphanumeric characters.
</p>
<p class="leafygreen-ui-1kp3ins">
You can include the same identifier multiple times in the update
document; however, for each distinct identifier (
<code class="leafygreen-ui-1l06pbn">
$[identifier]
</code>
)
in the update document, you must specify
<strong>
exactly one
</strong>
corresponding array filter document. That is, you cannot specify
multiple array filter documents for the same identifier. For
example, if the update statement includes the identifier
<code class="leafygreen-ui-1l06pbn">
x
</code>
(possibly multiple times), you cannot specify the following for
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
that includes 2 separate filter documents for
<code class="leafygreen-ui-1l06pbn">
x
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// INVALID\n\n[\n { \"x.a\": { $gt: 85 } },\n { \"x.b\": { $gt: 80 } }\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-comment">// INVALID</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><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span> } }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
However, you can specify compound conditions on the same identifier
in a single filter document, such as in the following examples:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"// Example 1\n[\n { $or: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 2\n[\n { $and: [{\"x.a\": {$gt: 85}}, {\"x.b\": {$gt: 80}}] }\n]\n// Example 3\n[\n { \"x.a\": { $gt: 85 }, \"x.b\": { $gt: 80 } }\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">// Example 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">$or</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 2</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$and</span>: <!-- -->[<!-- -->{<span class="lg-highlight-string">"x.a"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span>}}<!-- -->, <!-- -->{<span class="lg-highlight-string">"x.b"</span>: <!-- -->{<span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</span>}}] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx">]</td></tr><tr class=""><td class="leafygreen-ui-7razhx"><span class="lg-highlight-comment">// Example 3</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">[</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-string">"x.a"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">85</span> }<!-- -->, <span class="lg-highlight-string">"x.b"</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">80</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">
For examples, see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-findAndModify-arrayFilters" target="_self">
<span>
Specify
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
for an Array Update Operations
<!-- -->
.
</span>
</a>
</p>
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
is not available for updates that use an
aggregation pipeline.
</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-db.collection.findAndModify-let-syntax" target="_self">
<span>
let
</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-db.collection.findAndModify-let-syntax">
</span>
<p class="leafygreen-ui-1kp3ins">
Optional.
</p>
<p class="leafygreen-ui-1kp3ins">
Specifies a document with a list of variables. This allows you to
improve command readability by separating the variables from the query
text.
</p>
<p class="leafygreen-ui-1kp3ins">
The document syntax is:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n <variable_name_1>: <expression_1>,\n ...,\n <variable_name_n>: <expression_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"> <<!-- -->variable_name_1<!-- -->><!-- -->: <<!-- -->expression_1<!-- -->><!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->...<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <<!-- -->variable_name_n<!-- -->><!-- -->: <<!-- -->expression_n<!-- -->></td></tr><tr class=""><td class="leafygreen-ui-7razhx">}</td></tr></tbody></table></code></pre>
</div>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The variable is set to the value returned by the expression, and cannot
be changed afterwards.
</p>
<p class="leafygreen-ui-1kp3ins">
To access the value of a variable in the command, use the double
dollar sign prefix (
<code class="leafygreen-ui-1l06pbn">
$$
</code>
) together with your variable name in the form
<code class="leafygreen-ui-1l06pbn">
$$<variable_name>
</code>
. For example:
<code class="leafygreen-ui-1l06pbn">
$$targetTotal
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
To use a variable to filter results, you must access the variable
within the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
operator.
</p>
<p class="leafygreen-ui-1kp3ins">
For a complete example using
<code class="leafygreen-ui-1l06pbn">
let
</code>
and variables,
see
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-db.collection.findAndModify-let-example" target="_self">
<span>
Use Variables in
<code class="leafygreen-ui-1l06pbn">
let
</code>
.
</span>
</a>
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Return Data
<a class="headerlink leafygreen-ui-1kepx47" href="#return-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="return-data">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
For remove operations, if the query matches a document,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
returns the removed document.
If the query does not match a document to remove,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
For update operations,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
returns
one of the following:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If the
<code class="leafygreen-ui-1l06pbn">
new
</code>
parameter is not set or is
<code class="leafygreen-ui-1l06pbn">
false
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the pre-modification document if the query matches a document;
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
otherwise,
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If
<code class="leafygreen-ui-1l06pbn">
new
</code>
is
<code class="leafygreen-ui-1l06pbn">
true
</code>
:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the updated document if the query returns a match;
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
the inserted document if
<code class="leafygreen-ui-1l06pbn">
upsert: true
</code>
and no document matches the query;
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
otherwise,
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
</ul>
</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>
<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">
Retryable writes require the
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
method to copy the entire document into
a special side collection for each node in a replica set before it performs
the update. This can make
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
an expensive operation when dealing with
large documents or large replica sets.
</p>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
8.0
</em>
:
<!-- -->
To update the first document in a user-defined ordering with
better performance, 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 with the
<code class="leafygreen-ui-1l06pbn">
sort
</code>
option.
</p>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-fields-projection">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
<code class="leafygreen-ui-1l06pbn">
fields
</code>
Projection
<a class="headerlink leafygreen-ui-1kepx47" href="#fields-projection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="fields-projection">
</div>
</a>
</h3>
<div class="leafygreen-ui-85da11" role="note">
<h2 class="leafygreen-ui-1ac4g5h">
Important
</h2>
<h3 class="leafygreen-ui-144d5kf">
<strong>
Language Consistency
</strong>
</h3>
<div class="leafygreen-ui-9mycqc">
<p class="leafygreen-ui-1kp3ins">
As part of making
<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>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
projection consistent with
aggregation's
<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,
</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/method/db.collection.find/#mongodb-method-db.collection.find">
<code class="leafygreen-ui-1l06pbn">
find()
</code>
</a>
and
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
findAndModify()
</code>
</span>
</a>
projection can accept
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggregation expressions and syntax
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
MongoDB enforces additional restrictions with regards to
projections. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/limits/#mongodb-limit-Projection-Restrictions">
Projection Restrictions
</a>
for details.
</p>
</li>
</ul>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
fields
</code>
option takes a document in the following form:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ field1: <value>, field2: <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">{ <span class="lg-highlight-attr">field1</span>: <<!-- -->value<!-- -->><!-- -->,<!-- --> <span class="lg-highlight-attr">field2</span>: <<!-- -->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>
<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>
Projection
</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">
<field>: <1 or true>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies the inclusion of a field. If you specify a non-zero
integer for the projection value, the operation treats the
value as
<code class="leafygreen-ui-1l06pbn">
true
</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">
<field>: <0 or false>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
Specifies the exclusion of a field.
</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">
"<field>.$": <1 or true>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Uses the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/positional/#mongodb-projection-proj.-">
<code class="leafygreen-ui-1l06pbn">
$
</code>
</a>
array projection operator to return
the first element that matches the query condition on the
array field. If you specify a non-zero integer for the
projection value, the operation treats the value as
<code class="leafygreen-ui-1l06pbn">
true
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
Not available for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
views
<!-- -->
.
</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">
<field>: <array projection>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Uses the array projection operators (
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/elemMatch/#mongodb-projection-proj.-elemMatch">
<code class="leafygreen-ui-1l06pbn">
$elemMatch
</code>
</a>
,
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/projection/slice/#mongodb-projection-proj.-slice">
<code class="leafygreen-ui-1l06pbn">
$slice
</code>
</a>
) to specify the array elements to
include.
</p>
<p class="leafygreen-ui-1kp3ins">
Not available for
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/views/#std-label-views-landing-page">
views
<!-- -->
.
</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">
<field>: <aggregation expression>
</code>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
<p class="leafygreen-ui-1kp3ins">
Specifies the value of the projected field.
</p>
<p class="leafygreen-ui-1kp3ins">
With the use of
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/#std-label-aggregation-expressions">
aggregation
expressions and syntax
</a>
, including the
use of literals and aggregation variables, you can project new
fields or project existing fields with new values.
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you specify a non-numeric, non-boolean literal (such as a
literal string or an array or an operator expression) for
the projection value, the field is projected with the new
value, for example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: [ 1, 2, 3, "$someExistingField" ] }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: "New String Value" }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: { status: "Active", total: { $sum: "$existingArray" } } }
</code>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
To project a literal value for a field, use the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/literal/#mongodb-expression-exp.-literal">
<code class="leafygreen-ui-1l06pbn">
$literal
</code>
</a>
aggregation expression, for example:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: { $literal: 5 } }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: { $literal: true } }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
{ field: { $literal: { fieldWithValue0: 0, fieldWithValue1: 1 } } }
</code>
</p>
</li>
</ul>
</li>
</ul>
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Embedded Field Specification
<a class="headerlink leafygreen-ui-1kepx47" href="#embedded-field-specification" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-field-specification">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
For fields in an embedded documents, you can specify the field using
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/core/document/#std-label-document-dot-notation-embedded-fields">
dot notation
</a>
, for example
<code class="leafygreen-ui-1l06pbn">
"field.nestedfield": <value>
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
nested form, for example
<code class="leafygreen-ui-1l06pbn">
{ field: { nestedfield: <value> } }
</code>
</p>
</li>
</ul>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
<code class="leafygreen-ui-1l06pbn">
_id
</code>
Field Projection
<a class="headerlink leafygreen-ui-1kepx47" href="#_id-field-projection" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="_id-field-projection">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is included in the returned documents by default unless
you explicitly specify
<code class="leafygreen-ui-1l06pbn">
_id: 0
</code>
in the projection to suppress the field.
</p>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Inclusion or Exclusion
<a class="headerlink leafygreen-ui-1kepx47" href="#inclusion-or-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="inclusion-or-exclusion">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
A
<code class="leafygreen-ui-1l06pbn">
projection
</code>
<em>
cannot
</em>
contain
<em>
both
</em>
include and exclude
specifications, with the exception of the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In projections that
<em>
explicitly include
</em>
fields, the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is
the only field that you can
<em>
explicitly exclude
</em>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
In projections that
<em>
explicitly excludes
</em>
fields, the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field
is the only field that you can
<em>
explicitly include
</em>
; however, the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field is included by default.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
For more information on projection, see also:
</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/project-fields-from-query-results/#std-label-read-operations-projection">
Project Fields to Return from Query
</a>
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-upsert-and-unique-index">
</span>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upsert with Unique Index
<a class="headerlink leafygreen-ui-1kepx47" href="#upsert-with-unique-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="upsert-with-unique-index">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Upserts can create duplicate documents, unless there is a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/index-unique/#std-label-index-type-unique">
unique index
</a>
to prevent duplicates.
</p>
<p class="leafygreen-ui-1kp3ins">
Consider an example where no document with the name
<code class="leafygreen-ui-1l06pbn">
Andy
</code>
exists
and multiple clients issue the following command at roughly the same
time:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify(\n {\n query: { name: \"Andy\" },\n update: { $inc: { score: 1 } },\n upsert: true\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">people</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</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">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">)</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 all
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operations finish the query phase before any
client successfully inserts data,
<strong>
and
</strong>
there is no unique index on
the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field, each
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operation may result in an
insert, creating multiple documents with
<code class="leafygreen-ui-1l06pbn">
name: Andy
</code>
.
</p>
<p class="leafygreen-ui-1kp3ins">
A unique index on the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field ensures that only one document
is created. With a unique index in place, the multiple
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operations now exhibit the following behavior:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Exactly one
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operation will successfully insert a new
document.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Other
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operations either update the newly-inserted
document or fail due to a unique key collision.
</p>
<p class="leafygreen-ui-1kp3ins">
In order for other
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.findOneAndUpdate/#mongodb-method-db.collection.findOneAndUpdate">
<code class="leafygreen-ui-1l06pbn">
findOneAndUpdate()
</code>
</a>
operations to update the
newly-inserted document,
<strong>
all
</strong>
of the following conditions must
be met:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The target collection has a unique index that would cause a
duplicate key error.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The update operation is not
<code class="leafygreen-ui-1l06pbn">
updateMany
</code>
or
<code class="leafygreen-ui-1l06pbn">
multi
</code>
is
<code class="leafygreen-ui-1l06pbn">
false
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The update match condition is either:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A single equality predicate. For example
<code class="leafygreen-ui-1l06pbn">
{ "fieldA" : "valueA" }
</code>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
A logical AND of equality predicates. For example
<code class="leafygreen-ui-1l06pbn">
{ "fieldA" :
"valueA", "fieldB" : "valueB" }
</code>
</p>
</li>
</ul>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The fields in the equality predicate match the fields in the
unique index key pattern.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The update operation does not modify any fields in the
unique index key pattern.
</p>
</li>
</ul>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
The following table shows examples of
<code class="leafygreen-ui-1l06pbn">
upsert
</code>
operations that,
when a key collision occurs, either result in an update or fail.
</p>
<div class="leafygreen-ui-skkc39" tabindex="0">
<table class="leafygreen-ui-hr8lsv">
<colgroup>
<col style="width:30%"/>
<col style="width:40%"/>
<col style="width:30%"/>
</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>
Unique Index Key Pattern
</div>
</div>
</th>
<th class="leafygreen-ui-13uteka" role="columnheader" scope="col">
<div class="leafygreen-ui-ui0te9">
<div>
Update Operation
</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":"{ name : 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</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":"db.people.updateOne(\n { name: \"Andy\" },\n { $inc: { score: 1 } },\n { upsert: true }\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">db.<span class="lg-highlight-property">people</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">"Andy"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$inc</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">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>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The
<code class="leafygreen-ui-1l06pbn">
score
</code>
field of the matched document is incremented by
1.
</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":"{ name : 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</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":"db.people.updateOne(\n { name: { $ne: \"Joe\" } },\n { $set: { name: \"Andy\" } },\n { upsert: true }\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">db.<span class="lg-highlight-property">people</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-attr">$ne</span>: <span class="lg-highlight-string">"Joe"</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Andy"</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>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The operation fails because it modifies the field in the
unique index key pattern (
<code class="leafygreen-ui-1l06pbn">
name
</code>
).
</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":"{ name : 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">{ <!-- -->name <!-- -->: <span class="lg-highlight-number">1</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":"db.people.updateOne(\n { name: \"Andy\", email: \"[email protected]\" },\n { $set: { active: false } },\n { upsert: true }\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">db.<span class="lg-highlight-property">people</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">"Andy"</span>, <span class="lg-highlight-attr">email</span>: <span class="lg-highlight-string">"[email protected]"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">active</span>: <span class="lg-highlight-literal">false</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>
</div>
</div>
</div>
</div>
</td>
<td class="leafygreen-ui-1drjk7h">
<div class="leafygreen-ui-1n4j8xf">
<div>
The operation fails because the equality predicate fields
(
<code class="leafygreen-ui-1l06pbn">
name
</code>
,
<code class="leafygreen-ui-1l06pbn">
email
</code>
) do not match the index key field
(
<code class="leafygreen-ui-1l06pbn">
name
</code>
).
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<span class="leafygreen-ui-1qnjd6d" id="std-label-method-findAndModify-sharded-collection">
</span>
</section>
<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">
To use
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/command/findAndModify/#mongodb-dbcommand-dbcmd.findAndModify">
<code class="leafygreen-ui-1l06pbn">
findAndModify
</code>
</a>
on a sharded collection:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If you only target one shard, you can use a partial shard key in the
<code class="leafygreen-ui-1l06pbn">
query
</code>
field or,
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You can provide an equality condition on a full shard key in the
<code class="leafygreen-ui-1l06pbn">
query
</code>
field.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
Starting in version 7.1, you do not need to provide the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-shard-key">
shard key
</a>
or
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field in the query specification.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Documents in a sharded collection can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing">
missing the shard key fields
</a>
. To target a
document that is missing the shard key, you can use the
<code class="leafygreen-ui-1l06pbn">
null
</code>
equality match
<strong class="css-4dei7l">
in conjunction with
</strong>
another filter condition
(such as on the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field). For example:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: <value>, <shardkeyfield>: null } // _id of the document missing shard key","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">_id</span>: <<!-- -->value<!-- -->><!-- -->,<!-- --> <!-- --><<!-- -->shardkeyfield<!-- -->><!-- -->: <span class="lg-highlight-literal">null</span> } <span class="lg-highlight-comment">// _id of</span><span class="lg-highlight-comment"> the document missing </span><span class="lg-highlight-comment">shard key</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Shard Key Modification
<a class="headerlink leafygreen-ui-1kepx47" href="#shard-key-modification" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-key-modification">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
You can update a document's shard key value unless the shard key field is the
immutable
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field.
</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">
Documents in sharded collections can be missing the shard key fields.
Take precaution to avoid accidentally removing the shard key when changing
a document's shard key value.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
To update the
<strong>
existing
</strong>
shard key value with
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
:
</span>
</a>
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
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>
. Do
<strong class="css-4dei7l">
not
</strong>
issue the operation directly on the shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
run either in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
transaction
</a>
or as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/">
retryable write
<!-- -->
.
</a>
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
include an equality filter on the full shard key.
</p>
</li>
</ul>
<span class="leafygreen-ui-1qnjd6d" id="std-label-method-findAndModify-missing-shard-key">
</span>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Missing Shard Key
<a class="headerlink leafygreen-ui-1kepx47" href="#missing-shard-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="missing-shard-key">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Documents in a sharded collection can be
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/sharding-shard-key/#std-label-shard-key-missing">
missing the shard key fields
</a>
. To use
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
to set the document's
<strong>
missing
</strong>
shard key:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
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>
. Do
<strong class="css-4dei7l">
not
</strong>
issue the operation directly on the shard.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
run either in a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/">
transaction
</a>
or as a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/retryable-writes/">
retryable write
</a>
if the new shard key value is not
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
You
<strong class="css-4dei7l">
must
</strong>
include an equality filter on the full shard key.
</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">
Since a missing key value is returned as part of a null equality
match, to avoid updating a null-valued key, include additional
query conditions (such as on the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field) as appropriate.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
See also:
</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/sharding-shard-key/#std-label-shard-key-missing">
Missing Shard Key Fields
</a>
</p>
</li>
</ul>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Document Validation
<a class="headerlink leafygreen-ui-1kepx47" href="#document-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="document-validation">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
method adds support for the
<code class="leafygreen-ui-1l06pbn">
bypassDocumentValidation
</code>
option, which lets you bypass
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/schema-validation/#std-label-schema-validation-overview">
document validation
</a>
when
inserting or updating documents in a collection with validation
rules.
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-method-and-update">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Comparisons with the
<code class="leafygreen-ui-1l06pbn">
update
</code>
Method
<a class="headerlink leafygreen-ui-1kepx47" href="#comparisons-with-the-update-method" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="comparisons-with-the-update-method">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
When updating a document,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
updateOne()
</code>
</a>
method operate differently:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
If multiple documents match the update criteria, for
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
, you can specify a
<code class="leafygreen-ui-1l06pbn">
sort
</code>
to provide some
measure of control on which document to update.
</p>
<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">
updateOne()
</code>
</a>
updates the first document that
matches.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
By default,
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
returns
<!-- -->
the pre-modified version of the document
<!-- -->
. To
obtain the updated document, use the
<code class="leafygreen-ui-1l06pbn">
new
</code>
option.
</p>
<p class="leafygreen-ui-1kp3ins">
The
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
updateOne()
</code>
</a>
method returns a
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/WriteResult/#mongodb-method-WriteResult">
<code class="leafygreen-ui-1l06pbn">
WriteResult()
</code>
</a>
object that contains the status of the operation.
</p>
<p class="leafygreen-ui-1kp3ins">
To return the updated document, use 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. However, other updates may have modified the document between
your update and the document retrieval. Also, if the update modified
only a single document but multiple documents matched, you will need to
use additional logic to identify the updated document.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
When modifying a
<em>
single
</em>
document, both
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
and the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/method/db.collection.updateOne/#mongodb-method-db.collection.updateOne">
<code class="leafygreen-ui-1l06pbn">
updateOne()
</code>
</a>
method
<em>
atomically
</em>
update the
document. See
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/write-operations-atomicity/">
Atomicity and Transactions
</a>
for more
details about interactions and order of operations of these methods.
</p>
</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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
can be used inside
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions">
distributed transactions
<!-- -->
.
</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">
In most cases, a distributed transaction incurs a greater
performance cost over single document writes, and the
availability of distributed transactions should not be a
replacement for effective schema design. For many scenarios, the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/data-modeling/concepts/embedding-vs-references/#std-label-data-modeling-embedding">
denormalized data model (embedded documents and arrays)
</a>
will continue to be optimal for your
data and use cases. That is, for many scenarios, modeling your data
appropriately will minimize the need for distributed
transactions.
</p>
<p class="leafygreen-ui-1kp3ins">
For additional transactions usage considerations
(such as runtime limit and oplog size limit), see also
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions-production-consideration/#std-label-production-considerations">
Production Considerations
<!-- -->
.
</a>
</p>
</div>
</div>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Upsert within Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#upsert-within-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="upsert-within-transactions">
</div>
</a>
</h4>
<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">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
with
<code class="leafygreen-ui-1l06pbn">
upsert: true
</code>
can be run on an existing
collection or a non-existing collection. If run on a non-existing
collection, the operation creates the 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/transactions/#std-label-transactions-create-collections-indexes">
Create Collections and Indexes in a Transaction
</a>
</p>
</div>
</div>
</section>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Write Concerns and Transactions
<a class="headerlink leafygreen-ui-1kepx47" href="#write-concerns-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="write-concerns-and-transactions">
</div>
</a>
</h4>
<p class="leafygreen-ui-1kp3ins">
Do not explicitly set the write concern for the operation if run in
a transaction. To use write concern with transactions, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/transactions/#std-label-transactions-write-concern">
Transactions and Write Concern
<!-- -->
.
</a>
</p>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Oplog Entries
<a class="headerlink leafygreen-ui-1kepx47" href="#oplog-entries" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="oplog-entries">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
If a
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
operation successfully finds and
modifies a document, the operation adds an entry on the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/glossary/#std-term-oplog">
oplog
</a>
(operations log). If the operation fails or does not find a document to
modify, the operation does not add an entry on the oplog.
</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">
Update and Return
<a class="headerlink leafygreen-ui-1kepx47" href="#update-and-return" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-and-return">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following method updates and returns an existing document in the
people collection where the document matches the query criteria:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify({\n query: { name: \"Tom\", state: \"active\", rating: { $gt: 10 } },\n sort: { rating: 1 },\n update: { $inc: { score: 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">db.<span class="lg-highlight-property">people</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Tom"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <!-- -->{ <span class="lg-highlight-attr">$gt</span>: <span class="lg-highlight-number">10</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</span>: <!-- -->{ <span class="lg-highlight-attr">score</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">
This method performs the following actions:
</p>
<ol class="leafygreen-ui-rioki0" type="1">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
query
</code>
finds a document in the
<code class="leafygreen-ui-1l06pbn">
people
</code>
collection
where the
<code class="leafygreen-ui-1l06pbn">
name
</code>
field has the value
<code class="leafygreen-ui-1l06pbn">
Tom
</code>
, the
<code class="leafygreen-ui-1l06pbn">
state
</code>
field has the value
<code class="leafygreen-ui-1l06pbn">
active
</code>
and the
<code class="leafygreen-ui-1l06pbn">
rating
</code>
field has a
value
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/gt/#mongodb-query-op.-gt">
<code class="leafygreen-ui-1l06pbn">
greater than
</code>
</a>
10.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The
<code class="leafygreen-ui-1l06pbn">
sort
</code>
orders the results of the query in ascending order.
If multiple documents meet the
<code class="leafygreen-ui-1l06pbn">
query
</code>
condition, the method
will select for modification the first document as ordered by
this
<code class="leafygreen-ui-1l06pbn">
sort
</code>
.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The update
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/inc/#mongodb-update-up.-inc">
<code class="leafygreen-ui-1l06pbn">
increments
</code>
</a>
the value of the
<code class="leafygreen-ui-1l06pbn">
score
</code>
field by 1.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The method returns the original (i.e. pre-modification) document
selected for this update:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"50f1e2c99beb36a0f45c6453\"),\n \"name\" : \"Tom\",\n \"state\" : \"active\",\n \"rating\" : 100,\n \"score\" : 5\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"50f1e2c99beb36a0f45c6453"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Tom"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"active"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> <!-- -->: <span class="lg-highlight-number">100</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">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">
To return the updated document, add the
<code class="leafygreen-ui-1l06pbn">
new:true
</code>
option to
the method.
</p>
<p class="leafygreen-ui-1kp3ins">
If no document matched the
<code class="leafygreen-ui-1l06pbn">
query
</code>
condition, the method
returns
<code class="leafygreen-ui-1l06pbn">
null
</code>
.
</p>
</li>
</ol>
<span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-upsert-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Upsert
<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">
The following method includes the
<code class="leafygreen-ui-1l06pbn">
upsert: true
</code>
option for the
<code class="leafygreen-ui-1l06pbn">
update
</code>
operation to either update a matching document or, if no
matching document exists, create a new document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify({\n query: { name: \"Gus\", state: \"active\", rating: 100 },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } },\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">people</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">name</span>: <span class="lg-highlight-string">"Gus"</span>, <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span>, <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">100</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$inc</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">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 the method finds a matching document, the method performs an update.
</p>
<p class="leafygreen-ui-1kp3ins">
If the method does
<strong>
not
</strong>
find a matching document, the method creates
a new document. Because the method included the
<code class="leafygreen-ui-1l06pbn">
sort
</code>
option, it
returns an empty document
<code class="leafygreen-ui-1l06pbn">
{ }
</code>
as the original (pre-modification)
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ }","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">{ <!-- -->}</td></tr></tbody></table></code></pre>
<div class="leafygreen-ui-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 method did
<strong>
not
</strong>
include a
<code class="leafygreen-ui-1l06pbn">
sort
</code>
option, the method returns
<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":"null","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-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>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Return New Document
<a class="headerlink leafygreen-ui-1kepx47" href="#return-new-document" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-new-document">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The following method includes both the
<code class="leafygreen-ui-1l06pbn">
upsert: true
</code>
option and the
<code class="leafygreen-ui-1l06pbn">
new:true
</code>
option. The method either updates a matching document and
returns the updated document or, if no matching document exists,
inserts a document and returns the newly inserted document in the
<code class="leafygreen-ui-1l06pbn">
value
</code>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
In the following example, no document in the
<code class="leafygreen-ui-1l06pbn">
people
</code>
collection
matches the
<code class="leafygreen-ui-1l06pbn">
query
</code>
condition:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify({\n query: { name: \"Pascal\", state: \"active\", rating: 25 },\n sort: { rating: 1 },\n update: { $inc: { score: 1 } },\n upsert: true,\n new: true\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">db.people.findAndModify({</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> query: { name: "Pascal", state: "active", rating: 25 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> sort: { rating: 1 },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> update: { $inc: { score: 1 } },</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> upsert: true,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> new: true</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 method returns the newly inserted document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"50f49ad6444c11ac2448a5d6\"),\n \"name\" : \"Pascal\",\n \"rating\" : 25,\n \"score\" : 1,\n \"state\" : \"active\"\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"50f49ad6444c11ac2448a5d6"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"Pascal"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> <!-- -->: <span class="lg-highlight-number">25</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"active"</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-findAndModify-wrapper-sorted-remove">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Sort and Remove
<a class="headerlink leafygreen-ui-1kepx47" href="#sort-and-remove" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-and-remove">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
By including a
<code class="leafygreen-ui-1l06pbn">
sort
</code>
specification on the
<code class="leafygreen-ui-1l06pbn">
rating
</code>
field, the
following example removes from the
<code class="leafygreen-ui-1l06pbn">
people
</code>
collection a single
document with the
<code class="leafygreen-ui-1l06pbn">
state
</code>
value of
<code class="leafygreen-ui-1l06pbn">
active
</code>
and the lowest
<code class="leafygreen-ui-1l06pbn">
rating
</code>
among the matching documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.people.findAndModify(\n {\n query: { state: \"active\" },\n sort: { rating: 1 },\n remove: true\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">people</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">state</span>: <span class="lg-highlight-string">"active"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</span>: <!-- -->{ <span class="lg-highlight-attr">rating</span>: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">remove</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-1bqcprk" data-testid="leafygreen-code-panel">
<button aria-disabled="false" aria-label="Copy" class="leafygreen-ui-1c6zwke" data-testid="code_copy-button" tabindex="0">
<div class="leafygreen-ui-xhlipt">
<svg aria-label="Copy Icon" class="leafygreen-ui-1st74h4" height="16" role="img" viewbox="0 0 16 16" width="16">
<path clip-rule="evenodd" d="M1 5.71428V10.2857C1 11.2325 1.76751 12 2.71429 12H5.75V7.10957C5.75 6.54414 5.97724 6.00244 6.38065 5.60623L8.67403 3.35381C8.77447 3.25516 8.88376 3.16757 9 3.09182V2.71429C9 1.76751 8.23249 1 7.28571 1H5.8V4.42857C5.8 5.13865 5.22437 5.71428 4.51429 5.71428H1ZM9 4.78571L7.25654 6.49804C7.24689 6.50752 7.23749 6.5172 7.22834 6.52708C7.22208 6.53383 7.21594 6.54068 7.20991 6.54762C7.07504 6.70295 7 6.90234 7 7.10957V7.79762H9H10.0095C10.4829 7.79762 10.8667 7.41386 10.8667 6.94047V4H10.1505C9.92587 4 9.7102 4.0882 9.54992 4.24562L9 4.78571ZM4.86667 1H4.15053C3.92587 1 3.7102 1.0882 3.54992 1.24562L1.25654 3.49804C1.09244 3.65921 1 3.87957 1 4.10957V4.79762H4.00952C4.48291 4.79762 4.86667 4.41386 4.86667 3.94047V1ZM7 12V8.71428H9H10.5143C11.2244 8.71428 11.8 8.13865 11.8 7.42857V4H13.2857C14.2325 4 15 4.76751 15 5.71429V13.2857C15 14.2325 14.2325 15 13.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 method returns the deleted document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : ObjectId(\"52fba867ab5fdca1299674ad\"),\n \"name\" : \"XYZ123\",\n \"score\" : 1,\n \"state\" : \"active\",\n \"rating\" : 3\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-title lg-highlight-class">ObjectId</span>(<span class="lg-highlight-string">"52fba867ab5fdca1299674ad"</span>)<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"name"</span> <!-- -->: <span class="lg-highlight-string">"XYZ123"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"score"</span> <!-- -->: <span class="lg-highlight-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"state"</span> <!-- -->: <span class="lg-highlight-string">"active"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"rating"</span> <!-- -->: <span class="lg-highlight-number">3</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">
Specify Collation
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-collation" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-collation">
</div>
</a>
</h3>
<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">
A collection
<code class="leafygreen-ui-1l06pbn">
myColl
</code>
has the following documents:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{ _id: 1, category: \"café\", status: \"A\" }\n{ _id: 2, category: \"cafe\", status: \"a\" }\n{ _id: 3, category: \"cafE\", status: \"a\" }","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">_id</span>: <span class="lg-highlight-number">1</span>, <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"A"</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">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</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">category</span>: <span class="lg-highlight-string">"cafE"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</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 includes the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/collation/#std-label-collation">
collation
</a>
option:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.myColl.findAndModify({\n query: { category: \"cafe\", status: \"a\" },\n sort: { category: 1 },\n update: { $set: { status: \"Updated\" } },\n collation: { locale: \"fr\", strength: 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-property">myColl</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">category</span>: <span class="lg-highlight-string">"cafe"</span>, <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"a"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">sort</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">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-attr">status</span>: <span class="lg-highlight-string">"Updated"</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>, <span class="lg-highlight-attr">strength</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">
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\" : 1, \"category\" : \"café\", \"status\" : \"A\" }","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">"category"</span> <!-- -->: <span class="lg-highlight-string">"café"</span>, <span class="lg-highlight-string">"status"</span> <!-- -->: <span class="lg-highlight-string">"A"</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-findAndModify-arrayFilters">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Specify
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
for an Array Update Operations
<a class="headerlink leafygreen-ui-1kepx47" href="#specify-arrayfilters-for-an-array-update-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="specify-arrayfilters-for-an-array-update-operations">
</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">
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
is not available for updates that use an
aggregation pipeline.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
When updating an array field, you can specify
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
that
determine which array elements to update.
</p>
<section>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Update Elements Match
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
Criteria
<a class="headerlink leafygreen-ui-1kepx47" href="#update-elements-match-arrayfilters-criteria" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-elements-match-arrayfilters-criteria">
</div>
</a>
</h4>
<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">
arrayFilters
</code>
is not available for updates that use an
aggregation pipeline.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
students
</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.students.insertMany( [\n { \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] },\n { \"_id\" : 2, \"grades\" : [ 98, 100, 102 ] },\n { \"_id\" : 3, \"grades\" : [ 95, 110, 100 ] }\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">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><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 elements that are greater than or equal to
<code class="leafygreen-ui-1l06pbn">
100
</code>
in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array, use the filtered positional operator
<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>
with the
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
option in the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
method:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students.findAndModify({\n query: { grades: { $gte: 100 } },\n update: { $set: { \"grades.$[element]\" : 100 } },\n arrayFilters: [ { \"element\": { $gte: 100 } } ]\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">findAndModify</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <span class="lg-highlight-attr">grades</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[element]"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"element"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</span>: <span class="lg-highlight-number">100</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 updates the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
field for a single document, and
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":"{ \"_id\" : 1, \"grades\" : [ 95, 92, 90 ] }\n{ \"_id\" : 2, \"grades\" : [ 98, 100, 100 ] }\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="leafygreen-ui-1wr1lm6"><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">100</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>
<h4 class="contains-headerlink leafygreen-ui-1vzlt5f">
Update Specific Elements of an Array of Documents
<a class="headerlink leafygreen-ui-1kepx47" href="#update-specific-elements-of-an-array-of-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="update-specific-elements-of-an-array-of-documents">
</div>
</a>
</h4>
<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">
arrayFilters
</code>
is not available for updates that use an
aggregation pipeline.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
students2
</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.students2.insertMany( [\n {\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 }\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">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><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 finds a document where the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field equals
<code class="leafygreen-ui-1l06pbn">
1
</code>
and uses the filtered positional operator
<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>
with
the
<code class="leafygreen-ui-1l06pbn">
arrayFilters
</code>
to update the
<code class="leafygreen-ui-1l06pbn">
mean
</code>
for all elements in the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
array where the grade is greater than or equal to
<code class="leafygreen-ui-1l06pbn">
85
</code>
.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.findAndModify({\n query: { _id : 1 },\n update: { $set: { \"grades.$[elem].mean\" : 100 } },\n arrayFilters: [ { \"elem.grade\": { $gte: 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">students2</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>(<!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{ <!-- -->_id <!-- -->: <span class="lg-highlight-number">1</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"grades.$[elem].mean"</span> <!-- -->: <span class="lg-highlight-number">100</span> } }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">arrayFilters</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-string">"elem.grade"</span>: <!-- -->{ <span class="lg-highlight-attr">$gte</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>
<p class="leafygreen-ui-1kp3ins">
The operation updates the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
field for a single document, and 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\" : 100, \"std\" : 4 },\n { \"grade\" : 85, \"mean\" : 100, \"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="leafygreen-ui-1wr1lm6"><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">100</span>, <span class="lg-highlight-string">"std"</span> <!-- -->: <span class="lg-highlight-number">4</span> }<!-- -->,</td></tr><tr class="leafygreen-ui-1wr1lm6"><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">100</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>
<span class="leafygreen-ui-1qnjd6d" id="std-label-findAndModify-agg-pipeline">
</span>
</section>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use an Aggregation Pipeline for Updates
<a class="headerlink leafygreen-ui-1kepx47" href="#use-an-aggregation-pipeline-for-updates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-an-aggregation-pipeline-for-updates">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#mongodb-method-db.collection.findAndModify" target="_self">
<span>
<code class="leafygreen-ui-1l06pbn">
db.collection.findAndModify()
</code>
</span>
</a>
can accept an aggregation pipeline for
the update. The pipeline can consist of the following 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>
<p class="leafygreen-ui-1kp3ins">
Using the aggregation pipeline allows for a more expressive update
statement, such as expressing conditional updates based on current
field values or updating one field using the value of another field(s).
</p>
<p class="leafygreen-ui-1kp3ins">
For example, create a collection
<code class="leafygreen-ui-1l06pbn">
students2
</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.students2.insertMany( [\n {\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 }\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">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><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 finds a document where the
<code class="leafygreen-ui-1l06pbn">
_id
</code>
field equals
<code class="leafygreen-ui-1l06pbn">
1
</code>
and uses an aggregation pipeline to calculate a new field
<code class="leafygreen-ui-1l06pbn">
total
</code>
from the
<code class="leafygreen-ui-1l06pbn">
grades
</code>
field:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.students2.findAndModify( {\n query: { \"_id\" : 1 },\n update: [ { $set: { \"total\" : { $sum: \"$grades.grade\" } } } ], // The $set stage is an alias for ``$addFields`` stage\n new: 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">students2</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</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">update</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">$set</span>: <!-- -->{ <span class="lg-highlight-string">"total"</span> <!-- -->: <!-- -->{ <span class="lg-highlight-attr">$sum</span>: <span class="lg-highlight-string">"$grades.grade"</span> } } } ]<!-- -->, <span class="lg-highlight-comment">// The $set stage is an alias for ``$addFields`` stage</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">new</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>
<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
<code class="leafygreen-ui-1l06pbn">
$set
</code>
used in the pipeline refers to the aggregation stage
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/set/#mongodb-pipeline-pipe.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
</a>
and not the update operator
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/update/set/#mongodb-update-up.-set">
<code class="leafygreen-ui-1l06pbn">
$set
</code>
.
</a>
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
The operation returns the
<em>
updated
</em>
document:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"{\n \"_id\" : 1,\n \"grades\" : [ { \"grade\" : 80, \"mean\" : 75, \"std\" : 6 }, { \"grade\" : 85, \"mean\" : 90, \"std\" : 4 }, { \"grade\" : 85, \"mean\" : 85, \"std\" : 6 } ],\n \"total\" : 250\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-number">1</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-string">"grades"</span> <!-- -->: <!-- -->[ <!-- -->{ <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> }<!-- -->, <!-- -->{ <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> }<!-- -->, <!-- -->{ <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"> <span class="lg-highlight-string">"total"</span> <!-- -->: <span class="lg-highlight-number">250</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-db.collection.findAndModify-let-example">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Use Variables in
<code class="leafygreen-ui-1l06pbn">
let
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#use-variables-in-let" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-variables-in-let">
</div>
</a>
</h3>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.0
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
To define variables that you can access elsewhere in the command, use
the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-db.collection.findAndModify-let-syntax" target="_self">
<span>
let
</span>
</a>
option.
</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">
To filter results using a variable, you must access the variable
within the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/query/expr/#mongodb-query-op.-expr">
<code class="leafygreen-ui-1l06pbn">
$expr
</code>
</a>
operator.
</p>
</div>
</div>
<p class="leafygreen-ui-1kp3ins">
Create a collection
<code class="leafygreen-ui-1l06pbn">
cakeFlavors
</code>
:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.insertMany( [\n { _id: 1, flavor: \"chocolate\" },\n { _id: 2, flavor: \"strawberry\" },\n { _id: 3, flavor: \"cherry\" }\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">cakeFlavors</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">flavor</span>: <span class="lg-highlight-string">"chocolate"</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">flavor</span>: <span class="lg-highlight-string">"strawberry"</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">flavor</span>: <span class="lg-highlight-string">"cherry"</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 example defines a
<code class="leafygreen-ui-1l06pbn">
targetFlavor
</code>
variable in
<code class="leafygreen-ui-1l06pbn">
let
</code>
and
uses the variable to change the cake flavor from cherry to orange:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.cakeFlavors.findAndModify( {\n query: {\n $expr: { $eq: [ \"$flavor\", \"$$targetFlavor\" ] }\n },\n update: { flavor: \"orange\" },\n let: { targetFlavor: \"cherry\" }\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">cakeFlavors</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <!-- -->[ <span class="lg-highlight-string">"$flavor"</span>, <span class="lg-highlight-string">"$$targetFlavor"</span> ] }</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{ <span class="lg-highlight-attr">flavor</span>: <span class="lg-highlight-string">"orange"</span> }<!-- -->,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">let</span>: <!-- -->{ <span class="lg-highlight-attr">targetFlavor</span>: <span class="lg-highlight-string">"cherry"</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-findAndModify-example-user-roles-system-variable">
</span>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
User Roles and Document Updates
<a class="headerlink leafygreen-ui-1kepx47" href="#user-roles-and-document-updates" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-roles-and-document-updates">
</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 example in this section shows updates to fields in a collection
containing medical information. The example reads the current user roles
from the
<code class="leafygreen-ui-1l06pbn">
USER_ROLES
</code>
system variable and only performs the updates if
the user has a specific role.
</p>
<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">
The example creates these users:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
James
</code>
with a
<code class="leafygreen-ui-1l06pbn">
Billing
</code>
role.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
Michelle
</code>
with a
<code class="leafygreen-ui-1l06pbn">
Provider
</code>
role.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
Perform the following steps to create the roles, users, and collection:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Create roles named Billing and Provider with the required\nprivileges and resources.Run:","name":"Create the roles"},{"@type":"HowToStep","text":"Create users named James and Michelle with the required\nroles.","name":"Create the users"},{"@type":"HowToStep","text":"Run:","name":"Create the collection"}],"name":"User Roles and Document Updates","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">
Create roles named
<code class="leafygreen-ui-1l06pbn">
Billing
</code>
and
<code class="leafygreen-ui-1l06pbn">
Provider
</code>
with the required
privileges and resources.
</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.createRole( { role: \"Billing\", privileges: [ { resource: { db: \"test\",\n collection: \"medicalView\" }, actions: [ \"find\" ] } ], roles: [ ] } )\ndb.createRole( { role: \"Provider\", privileges: [ { resource: { db: \"test\",\n collection: \"medicalView\" }, actions: [ \"find\" ] } ], roles: [ ] } )","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">"Billing"</span>, <span class="lg-highlight-attr">privileges</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">resource</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">collection</span>: <span class="lg-highlight-string">"medicalView"</span> }<!-- -->, <span class="lg-highlight-attr">actions</span>: <!-- -->[ <span class="lg-highlight-string">"find"</span> ] } ]<!-- -->, <span class="lg-highlight-attr">roles</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">"Provider"</span>, <span class="lg-highlight-attr">privileges</span>: <!-- -->[ <!-- -->{ <span class="lg-highlight-attr">resource</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">collection</span>: <span class="lg-highlight-string">"medicalView"</span> }<!-- -->, <span class="lg-highlight-attr">actions</span>: <!-- -->[ <span class="lg-highlight-string">"find"</span> ] } ]<!-- -->, <span class="lg-highlight-attr">roles</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">
James
</code>
and
<code class="leafygreen-ui-1l06pbn">
Michelle
</code>
with the required
roles.
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"SoftwareSourceCode","codeSampleType":"code snippet","text":"db.createUser( {\n user: \"James\",\n pwd: \"js008\",\n roles: [\n { role: \"Billing\", db: \"test\" }\n ]\n} )\n\ndb.createUser( {\n user: \"Michelle\",\n pwd: \"me009\",\n roles: [\n { role: \"Provider\", 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">"James"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pwd</span>: <span class="lg-highlight-string">"js008"</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">"Billing"</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">"Michelle"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">pwd</span>: <span class="lg-highlight-string">"me009"</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">"Provider"</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.medical.insertMany( [\n {\n _id: 0,\n patientName: \"Jack Jones\",\n diagnosisCode: \"CAS 17\",\n creditCard: \"1234-5678-9012-3456\"\n },\n {\n _id: 1,\n patientName: \"Mary Smith\",\n diagnosisCode: \"ACH 01\",\n creditCard: \"6541-7534-9637-3456\"\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">medical</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">patientName</span>: <span class="lg-highlight-string">"Jack Jones"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">diagnosisCode</span>: <span class="lg-highlight-string">"CAS 17"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">creditCard</span>: <span class="lg-highlight-string">"1234-5678-9012-3456"</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">patientName</span>: <span class="lg-highlight-string">"Mary Smith"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">diagnosisCode</span>: <span class="lg-highlight-string">"ACH 01"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">creditCard</span>: <span class="lg-highlight-string">"6541-7534-9637-3456"</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">
Log in as as
<code class="leafygreen-ui-1l06pbn">
Michelle
</code>
, who has the
<code class="leafygreen-ui-1l06pbn">
Provider
</code>
role, and perform an
update:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Run:","name":"Log in as Michelle"},{"@type":"HowToStep","text":"Run:","name":"Perform update"}],"name":"User Roles and Document Updates","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
<code class="leafygreen-ui-1l06pbn">
Michelle
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#log-in-as-michelle" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-michelle">
</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( \"Michelle\", \"me009\" )","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">"Michelle"</span>, <span class="lg-highlight-string">"me009"</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">
Perform update
<a class="headerlink leafygreen-ui-1kepx47" href="#perform-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="perform-update">
</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":"// Attempt to find and modify document\ndb.medical.findAndModify( {\n query:\n { $and: [\n {\n // Only update the document for Mary Smith\n patientName: { $eq: \"Mary Smith\" }\n },\n {\n // User must have the Provider role to perform the update\n $expr: { $ne: [ {\n $setIntersection: [ [ \"Provider\" ], \"$$USER_ROLES.role\" ]\n }, [] ] }\n }\n ]\n },\n // Update document\n update: {\n patientName: \"Mary Smith\",\n diagnosisCode: \"ACH 03\",\n creditCard: \"6541-7534-9637-3456\"\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-comment">//</span><span class="lg-highlight-comment"> Attempt to find </span><span class="lg-highlight-comment">and modify document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">medical</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$and</span>: <!-- -->[</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"> Only update the </span><span class="lg-highlight-comment">document for Mary Smith</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <span class="lg-highlight-string">"Mary 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-comment">//</span><span class="lg-highlight-comment"> User must have </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Provider role to </span><span class="lg-highlight-comment">perform the update</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$ne</span>: <!-- -->[ <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"Provider"</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><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// Update document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <span class="lg-highlight-string">"Mary Smith"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">diagnosisCode</span>: <span class="lg-highlight-string">"ACH 03"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">creditCard</span>: <span class="lg-highlight-string">"6541-7534-9637-3456"</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">
The previous example uses
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/setIntersection/#mongodb-expression-exp.-setIntersection">
<code class="leafygreen-ui-1l06pbn">
$setIntersection
</code>
</a>
to return
documents where the intersection between the
<code class="leafygreen-ui-1l06pbn">
"Provider"
</code>
string and
the user roles from
<code class="leafygreen-ui-1l06pbn">
$$USER_ROLES.role
</code>
is not empty.
<code class="leafygreen-ui-1l06pbn">
Michelle
</code>
has
the
<code class="leafygreen-ui-1l06pbn">
Provider
</code>
role, so the update is performed.
</p>
<p class="leafygreen-ui-1kp3ins">
Next, log in as as
<code class="leafygreen-ui-1l06pbn">
James
</code>
, who does not have the
<code class="leafygreen-ui-1l06pbn">
Provider
</code>
role,
and attempt to perform the same update:
</p>
<script class="structured_data" type="application/ld+json">
{"@context":"https://schema.org","@type":"HowTo","steps":[{"@type":"HowToStep","text":"Run:","name":"Log in as James"},{"@type":"HowToStep","text":"Run:","name":"Attempt to perform update"}],"name":"User Roles and Document Updates","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
<code class="leafygreen-ui-1l06pbn">
James
</code>
<a class="headerlink leafygreen-ui-1kepx47" href="#log-in-as-james" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-james">
</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( \"James\", \"js008\" )","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">"James"</span>, <span class="lg-highlight-string">"js008"</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">
Attempt to perform update
<a class="headerlink leafygreen-ui-1kepx47" href="#attempt-to-perform-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="attempt-to-perform-update">
</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":"// Attempt to find and modify document\ndb.medical.findAndModify( {\n query:\n { $and: [\n {\n // Only update the document for Mary Smith\n patientName: { $eq: \"Mary Smith\" }\n },\n {\n // User must have the Provider role to perform the update\n $expr: { $ne: [ {\n $setIntersection: [ [ \"Provider\" ], \"$$USER_ROLES.role\" ]\n }, [] ] }\n }\n ]\n },\n // Update document\n update: {\n patientName: \"Mary Smith\",\n diagnosisCode: \"ACH 03\",\n creditCard: \"6541-7534-9637-3456\"\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-comment">//</span><span class="lg-highlight-comment"> Attempt to find </span><span class="lg-highlight-comment">and modify document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx">db.<span class="lg-highlight-property">medical</span>.<span class="lg-highlight-title lg-highlight-function">findAndModify</span>( <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">query</span>:</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <!-- -->{ <span class="lg-highlight-attr">$and</span>: <!-- -->[</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"> Only update the </span><span class="lg-highlight-comment">document for Mary Smith</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <!-- -->{ <span class="lg-highlight-attr">$eq</span>: <span class="lg-highlight-string">"Mary 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-comment">//</span><span class="lg-highlight-comment"> User must have </span><span class="lg-highlight-comment">the</span><span class="lg-highlight-comment"> Provider role to </span><span class="lg-highlight-comment">perform the update</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$expr</span>: <!-- -->{ <span class="lg-highlight-attr">$ne</span>: <!-- -->[ <!-- -->{</td></tr><tr class="leafygreen-ui-1wr1lm6"><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">$setIntersection</span>: <!-- -->[ <!-- -->[ <span class="lg-highlight-string">"Provider"</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><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-comment">// Update document</span></td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">update</span>: <!-- -->{</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">patientName</span>: <span class="lg-highlight-string">"Mary Smith"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">diagnosisCode</span>: <span class="lg-highlight-string">"ACH 03"</span>,</td></tr><tr class=""><td class="leafygreen-ui-7razhx"> <span class="lg-highlight-attr">creditCard</span>: <span class="lg-highlight-string">"6541-7534-9637-3456"</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">
The previous example does not update any documents.
</p>
</section>
</section>
</section>
|
https://www.mongodb.com/docs/manual/reference/sbe/ | <section>
<h1 class="contains-headerlink leafygreen-ui-41fr9s" weight="medium">
Slot-Based Query Execution Engine
<a class="headerlink leafygreen-ui-1kepx47" href="#slot-based-query-execution-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="slot-based-query-execution-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="#eligible-queries-for-the-slot-based-execution-engine" target="_self">
<span>
Eligible Queries for the Slot-Based Execution Engine
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#block-processing" target="_self">
<span>
Block Processing
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-cpmeq5" href="#determine-which-query-engine-was-used" target="_self">
<span>
Determine which Query Engine was Used
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#check-query-explain-results" target="_self">
<span>
Check Query Explain Results
</span>
</a>
</li>
<li class="leafygreen-ui-1jqtqlb">
<a class="lg-ui-0001 leafygreen-ui-x9koo9" href="#check-slow-query-logs" target="_self">
<span>
Check Slow Query Logs
</span>
</a>
</li>
</ul>
</div>
<div>
<p>
<em>
New
<!-- -->
in version
<!-- -->
5.1
</em>
.
</p>
</div>
<p class="leafygreen-ui-1kp3ins">
To find and return query results, MongoDB uses one of the following
query engines:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The classic query engine
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
The slot-based query execution engine, which is available for some queries starting in MongoDB
5.1.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
MongoDB automatically selects the engine to execute the query. In
MongoDB versions earlier than 8.0, you cannot manually specify an engine
for a particular query. Starting in MongoDB 8.0, you can use
query settings to specify an engine for queries. For details, 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>
<p class="leafygreen-ui-1kp3ins">
MongoDB can use the slot-based query execution engine for a subset of queries provided certain
conditions are met. In most cases, the slot-based execution engine provides improved
performance and lower CPU and memory costs compared to the classic query
engine.
</p>
<p class="leafygreen-ui-1kp3ins">
MongoDB uses the classic engine for queries that are ineligible for the
slot-based query execution engine.
</p>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Eligible Queries for the Slot-Based Execution Engine
<a class="headerlink leafygreen-ui-1kepx47" href="#eligible-queries-for-the-slot-based-execution-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="eligible-queries-for-the-slot-based-execution-engine">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
MongoDB determines eligibility for using the slot-based execution engine on a per-query basis,
and considers support for each operator and expressions present in the query.
For example, two common pipelines that use slot-based execution engine are aggregations with
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/group/#mongodb-pipeline-pipe.-group">
<code class="leafygreen-ui-1l06pbn">
$group
</code>
</a>
or
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/operator/aggregation/lookup/#mongodb-pipeline-pipe.-lookup">
<code class="leafygreen-ui-1l06pbn">
$lookup
</code>
</a>
stages. However, support for the
slot-based execution engine is version specific and actively changing.
</p>
<p class="leafygreen-ui-1kp3ins">
To see whether your query used the slot-based execution engine, refer to the
<a class="lg-ui-0001 leafygreen-ui-fgcsv5" href="#std-label-sbe-determine-query-engine" target="_self">
<span>
Determine which Query Engine was Used
</span>
</a>
section.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Block Processing
<a class="headerlink leafygreen-ui-1kepx47" href="#block-processing" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="block-processing">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in version 8.0, MongoDB may execute certain time series queries using
block processing. This performance improvement processes queries in "blocks" of
data, rather than individual values. Block processing improves query execution
speed and throughput when working with time series collections.
</p>
<p class="leafygreen-ui-1kp3ins">
To learn more, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/core/timeseries/timeseries-querying/#std-label-timeseries-querying-block-processing">
Querying Time Series Data
<!-- -->
.
</a>
</p>
<span class="leafygreen-ui-1qnjd6d" id="std-label-sbe-determine-query-engine">
</span>
</section>
</section>
<section>
<h2 class="contains-headerlink leafygreen-ui-19f71ei" weight="medium">
Determine which Query Engine was Used
<a class="headerlink leafygreen-ui-1kepx47" href="#determine-which-query-engine-was-used" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-5.047l2.884-2.871a3.542 3.542 0 0 1 5.025.022Z" fill="currentColor">
</path>
</svg>
<div class="css-1btu0w3 evvkmar0" id="determine-which-query-engine-was-used">
</div>
</a>
</h2>
<p class="leafygreen-ui-1kp3ins">
There are a few ways to determine whether the classic engine or the
slot-based execution engine was used to execute a query.
</p>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Query Explain Results
<a class="headerlink leafygreen-ui-1kepx47" href="#check-query-explain-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="check-query-explain-results">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
The explain results for a query differ based on
which query engine was used. For example, explain results for queries
executed using the slot-based execution engine include the
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/explain-results/#mongodb-data-explain.queryPlanner.winningPlan.slotBasedPlan">
<code class="leafygreen-ui-1l06pbn">
explain.queryPlanner.winningPlan.slotBasedPlan
</code>
</a>
field.
</p>
<p class="leafygreen-ui-1kp3ins">
For more information about the differences in explain results between
query engines, see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/explain-results/#std-label-explain-output-structure">
Explain Output Structure
<!-- -->
.
</a>
</p>
</section>
<section>
<h3 class="contains-headerlink leafygreen-ui-15ajumo" weight="medium">
Check Slow Query Logs
<a class="headerlink leafygreen-ui-1kepx47" href="#check-slow-query-logs" title="Permalink to this heading">
<svg aria-label="Link Icon" class="leafygreen-ui-a30zj9" fill="none" height="12" role="img" viewbox="0 0 16 16" width="12" xmlns="http://www.w3.org/2000/svg">
<path d="M6.039 9.953a3.596 3.596 0 0 1-.327-.38l1.45-1.445a1.553 1.553 0 0 0 2.496.423l2.885-2.87a1.57 1.57 0 0 0 .01-2.213 1.553 1.553 0 0 0-2.203-.01l-.379.377A.995.995 0 0 1 8.56 3.83a1.005 1.005 0 0 1 .006-1.418l.38-.377a3.542 3.542 0 0 1 5.024.023 3.58 3.58 0 0 1-.022 5.047l-2.884 2.871a3.542 3.542 0 0 1-5.025-.022Z" fill="currentColor">
</path>
<path d="M9.961 6.047c.12.12.228.248.327.38l-1.45 1.445a1.553 1.553 0 0 0-2.496-.423l-2.885 2.87a1.57 1.57 0 0 0-.01 2.213 1.553 1.553 0 0 0 2.203.01l.379-.377a.995.995 0 0 1 1.411.006 1.005 1.005 0 0 1-.006 1.418l-.38.377a3.542 3.542 0 0 1-5.024-.023 3.58 3.58 0 0 1 .022-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-slow-query-logs">
</div>
</a>
</h3>
<p class="leafygreen-ui-1kp3ins">
Starting in MongoDB 6.2, slow operation log messages include a
<code class="leafygreen-ui-1l06pbn">
queryFramework
</code>
field that indicates which query engine executed the
query:
</p>
<ul class="leafygreen-ui-rioki0">
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
queryFramework: "classic"
</code>
indicates that the classic engine
executed the query.
</p>
</li>
<li class="leafygreen-ui-d7p7b6">
<p class="leafygreen-ui-1kp3ins">
<code class="leafygreen-ui-1l06pbn">
queryFramework: "sbe"
</code>
indicates that the slot-based query execution engine executed the
query.
</p>
</li>
</ul>
<p class="leafygreen-ui-1kp3ins">
To see an example log message for a query that used the slot-based execution engine,
see
<a class="leafygreen-ui-tqgtui" href="/docs/manual/reference/log-messages/#std-label-log-message-json-examples-slow-op">
Slow Operation
<!-- -->
.
</a>
</p>
</section>
</section>
</section>
|
Subsets and Splits