-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathdb.collection.validate.txt
211 lines (139 loc) · 5.84 KB
/
db.collection.validate.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
========================
db.collection.validate()
========================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. include:: includes/wayfinding/mongosh-method-validate.rst
.. _validate-standalone-inconsistencies:
Description
-----------
.. versionchanged:: 6.2
.. method:: db.collection.validate(<documents>)
.. |dbcommand| replace:: :dbcommand:`validate` command
Validates a collection. The method scans a collection data and
indexes for correctness and returns the result. For details of the
output, see :ref:`validate-output`.
Starting in version 5.0, the :method:`db.collection.validate()`
method can also fix inconsistencies in the collection.
.. include:: /includes/fact-validate-standalone-inconsistencies.rst
The :method:`db.collection.validate()` method is a wrapper around
the :dbcommand:`validate` command.
Compatibility
-------------
.. |command| replace:: method
This method is available in deployments hosted in the following environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
.. include:: /includes/fact-environments-onprem-only.rst
Syntax
------
The :method:`db.collection.validate()` method has the following syntax:
.. code-block:: javascript
db.collection.validate( {
full: <boolean>, // Optional
repair: <boolean>, // Optional, added in MongoDB 5.0
checkBSONConformance: <boolean> // Optional, added in MongoDB 6.2
} )
Parameters
~~~~~~~~~~
The :method:`db.collection.validate()` method can take the
following optional document parameter with the fields:
.. list-table::
:header-rows: 1
:widths: 15 15 70
* - Field
- Type
- Description
* - :ref:`full <method-validate-full>`
- boolean
- .. _method-validate-full:
*Optional*. A flag that determines whether the command performs
a slower but more thorough check or a faster but less thorough
check.
- If ``true``, performs a more thorough check with the following
exception:
- Full validation on the ``oplog`` for WiredTiger skips the more
thorough check.
- If ``false``, omits some checks for a faster but less
thorough check.
The default is ``false``.
.. include:: /includes/fact-validate-wiredtiger-full-option.rst
* - :ref:`repair <method-validate-repair>`
- boolean
- .. _method-validate-repair:
.. include:: /includes/fact-validate-repair-option.rst
* - ``fixMultikey``
- boolean
- .. _method-validate-fixmultikey:
.. include:: /includes/fact-validate-fixmultikey.rst
* - :ref:`checkBSONConformance
<method-validate-checkBSONConformance>`
- boolean
- .. _method-validate-checkBSONConformance:
.. include:: /includes/fact-validate-conformance.rst
Behavior
--------
Performance
~~~~~~~~~~~
The :method:`db.collection.validate()` method is potentially resource
intensive and may impact the performance of your MongoDB instance,
particularly on larger data sets.
The :method:`db.collection.validate()` method obtains an exclusive lock
on the collection. This will block all reads and writes on the
collection until the operation finishes. When run on a secondary, the
operation can block all other operations on that secondary until it
finishes.
.. warning::
Validation has exclusive lock requirements that affect performance
on primaries and on secondaries that are servicing reads. Consider
only running :method:`db.collection.validate()` on nodes that are
not servicing reads or writes.
To minimize impact on the primary, the majority of the data-bearing
(non-arbiter), voting members in the cluster must be available and
must not have significant replication lag.
To minimize the impact of the validation operation on client
applications, run :method:`db.collection.validate()` on a secondary
node that is not servicing read requests. You can convert the
current primary node to a secondary node, by running the
:method:`rs.stepDown()` method.
To completely isolate the :method:`db.collection.validate()`
operation from client traffic, choose one of the following options:
- Isolate a replica set member by following the :ref:`rolling
maintenance procedure <perform-maint-on-replica-set>` to
temporarily remove it from the cluster.
- :ref:`Convert a secondary node
<configure-hidden-replica-set-member>` to a replica set
:ref:`hidden member <replica-set-hidden-members>` and perform the
validation on the hidden node.
Data Throughput Metrics
~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/extracts/4.4-validate-data-throughput.rst
Collection Validation Improvements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/validate-improvements-introduction.rst
Examples
--------
- To validate a collection ``myCollection`` using the default validation
setting (specifically, :ref:`full: false <method-validate-full>`):
.. code-block:: javascript
db.myCollection.validate()
db.myCollection.validate({ })
db.myCollection.validate( { full: false } )
- To perform a full validation of collection ``myCollection``, specify
:ref:`full: true <method-validate-full>`:
.. code-block:: javascript
db.myCollection.validate( { full: true } )
- To repair collection ``myCollection``, specify
:ref:`repair: true <method-validate-repair>`:
.. code-block:: javascript
db.myCollection.validate( { repair: true } )
- To perform additional BSON conformance checks in ``myCollection``,
specify :ref:`checkBSONConformance: true
<method-validate-checkBSONConformance>`:
.. code-block:: javascript
db.myCollection.validate( { checkBSONConformance: true } )
For details of the output, see :ref:`validate-output`.