@@ -24,7 +24,8 @@ Definition
24
24
25
25
db.runCommand( {
26
26
dbStats: 1,
27
- scale: <number> // Optional
27
+ scale: <number>,
28
+ freeStorage: 0
28
29
} )
29
30
30
31
The :dbcommand:`dbStats` command takes the following fields:
@@ -33,16 +34,13 @@ Definition
33
34
:header-rows: 1
34
35
:widths: 20 80
35
36
36
- * - Parameter
37
-
37
+ * - Fields
38
38
- Description
39
39
40
- * - ``dbStats``
41
-
40
+ * - :dbcommand:`dbStats`
42
41
- 1
43
42
44
43
* - :ref:`scale <dbStats-scale>`
45
-
46
44
- .. _dbStats-scale:
47
45
48
46
Optional. The scale factor for the various size data. The
@@ -57,6 +55,17 @@ Definition
57
55
58
56
.. include:: /includes/extracts/4.2-changes-stats-scaleFactor.rst
59
57
58
+ * - :ref:`freeStorage <dbStats-freeStorage>`
59
+ - .. _dbStats-freeStorage:
60
+
61
+ Optional. To return details on free space allocated to
62
+ collections, set ``freeStorage`` to 1.
63
+
64
+ If the instance has a large number of collections or indexes,
65
+ obtaining free space usage data may cause processing delays.
66
+ To gather :dbcommand:`dbStats` information without free space
67
+ details, either set ``freeStorage`` to 0 or do not include
68
+ the field.
60
69
61
70
In :binary:`~bin.mongosh`, the :method:`db.stats()` function
62
71
provides a wrapper around :dbcommand:`dbStats`.
@@ -151,9 +160,10 @@ Output
151
160
allocated to indexes. See :data:`~dbStats.indexFreeStorageSize` for
152
161
the total free index size.
153
162
154
- This value is always included in the :dbcommand:`dbStats` output.
163
+ To include this value in the :dbcommand:`dbStats` output, set
164
+ :ref:`freeStorage <dbStats-freeStorage>` to 1.
155
165
156
- .. versionadded:: 5.0
166
+ *Updated in version 5.0.6.*
157
167
158
168
.. data:: dbStats.indexes
159
169
@@ -174,7 +184,10 @@ Output
174
184
allocated to document storage. See :data:`~dbStats.freeStorageSize`
175
185
for the total free document storage size.
176
186
177
- .. versionadded:: 5.0
187
+ To include this value in the :dbcommand:`dbStats` output, set
188
+ :ref:`freeStorage <dbStats-freeStorage>` to 1.
189
+
190
+ *Updated in version 5.0.6.*
178
191
179
192
.. data:: dbStats.totalSize
180
193
@@ -192,7 +205,10 @@ Output
192
205
:data:`~dbStats.freeStorageSize` and
193
206
:data:`~dbStats.indexFreeStorageSize`.
194
207
195
- .. versionadded:: 5.0
208
+ To include this value in the :dbcommand:`dbStats` output, set
209
+ :ref:`freeStorage <dbStats-freeStorage>` to 1.
210
+
211
+ *Updated in version 5.0.6.*
196
212
197
213
.. data:: dbStats.scaleFactor
198
214
@@ -224,12 +240,66 @@ Output
224
240
Examples
225
241
--------
226
242
227
- If you are only interested in one field, the output of the
228
- :dbcommand:`dbStats` command can be limited to just that field. For
229
- example, the following command returns the current total free
230
- storage size.
243
+ The following examples demonstrate :dbcommand:`dbStats` usage.
244
+
245
+ Limit Data Returned
246
+ ~~~~~~~~~~~~~~~~~~~
247
+
248
+ To limit the data returned to a single field, append the field name to
249
+ the :dbcommand:`dbStats` command. This example returns the
250
+ :data:`~dbStats.indexSize` value:
231
251
232
252
.. code-block:: javascript
233
253
234
- db.runCommand( { dbStats: 1 } ).freeStorageSize
235
-
254
+ db.runCommand( { dbStats: 1 } ).indexSize
255
+
256
+ View Free Space Allocated to Collections
257
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258
+
259
+ To view free storage usage, set :ref:`freeStorage
260
+ <dbStats-freeStorage>` to 1.
261
+
262
+ .. code-block:: javascript
263
+
264
+ db.runCommand( { dbStats: 1, scale: 1024, freeStorage: 1 } )
265
+
266
+ Example output:
267
+
268
+ .. code-block:: javascript
269
+ :copyable: false
270
+ :emphasize-lines: 9, 12, 14
271
+
272
+ {
273
+ db: 'test',
274
+ collections: 2,
275
+ views: 0,
276
+ objects: 1689,
277
+ avgObjSize: 52.56542332741267,
278
+ dataSize: 86.7021484375,
279
+ storageSize: 100,
280
+ freeStorageSize: 32,
281
+ indexes: 2,
282
+ indexSize: 116,
283
+ indexFreeStorageSize: 36,
284
+ totalSize: 216,
285
+ totalFreeStorageSize: 68,
286
+ scaleFactor: 1024,
287
+ fsUsedSize: 60155820,
288
+ fsTotalSize: 61255492,
289
+ ok: 1,
290
+ '$clusterTime': {
291
+ clusterTime: Timestamp({ t: 1646085664, i: 1 }),
292
+ signature: {
293
+ hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
294
+ keyId: Long("0")
295
+ }
296
+ },
297
+ operationTime: Timestamp({ t: 1646085664, i: 1 })
298
+ }
299
+
300
+ The :ref:`freeStorage <dbStats-freeStorage>` field enables
301
+ the collection and display of the highlighted metrics.
302
+
303
+ The :ref:`scale <dbStats-scale>` field sets the displayed values to
304
+ kilobytes.
305
+
0 commit comments