@@ -24,7 +24,8 @@ Definition
2424
2525 db.runCommand( {
2626 dbStats: 1,
27- scale: <number> // Optional
27+ scale: <number>,
28+ freeStorage: 0
2829 } )
2930
3031 The :dbcommand:`dbStats` command takes the following fields:
@@ -33,16 +34,13 @@ Definition
3334 :header-rows: 1
3435 :widths: 20 80
3536
36- * - Parameter
37-
37+ * - Fields
3838 - Description
3939
40- * - ``dbStats``
41-
40+ * - :dbcommand:`dbStats`
4241 - 1
4342
4443 * - :ref:`scale <dbStats-scale>`
45-
4644 - .. _dbStats-scale:
4745
4846 Optional. The scale factor for the various size data. The
@@ -57,6 +55,17 @@ Definition
5755
5856 .. include:: /includes/extracts/4.2-changes-stats-scaleFactor.rst
5957
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.
6069
6170 In :binary:`~bin.mongosh`, the :method:`db.stats()` function
6271 provides a wrapper around :dbcommand:`dbStats`.
@@ -151,9 +160,10 @@ Output
151160 allocated to indexes. See :data:`~dbStats.indexFreeStorageSize` for
152161 the total free index size.
153162
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.
155165
156- .. versionadded:: 5.0
166+ *Updated in version 5.2.1, and 5.0.6.*
157167
158168.. data:: dbStats.indexes
159169
@@ -174,7 +184,10 @@ Output
174184 allocated to document storage. See :data:`~dbStats.freeStorageSize`
175185 for the total free document storage size.
176186
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.2.1, and 5.0.6.*
178191
179192.. data:: dbStats.totalSize
180193
@@ -192,7 +205,10 @@ Output
192205 :data:`~dbStats.freeStorageSize` and
193206 :data:`~dbStats.indexFreeStorageSize`.
194207
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.2.1, and 5.0.6.*
196212
197213.. data:: dbStats.scaleFactor
198214
@@ -224,12 +240,66 @@ Output
224240Examples
225241--------
226242
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:
231251
232252.. code-block:: javascript
233253
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