Skip to content

DOCS-14020 documents listDatabase output changes for 5.0 #5264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 64 additions & 27 deletions source/reference/command/listDatabases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,37 +101,14 @@ Definition

.. versionadded:: 4.4


Output
------

:dbcommand:`listDatabases` returns a document that contains:

- A field named ``databases`` whose value is an array of documents, one
document for each database. Each document contains:

- A ``name`` field with the database name.

- A ``sizeOnDisk`` field with the total size of the database files on
disk in bytes.

- An ``empty`` field specifying whether the database has any data.

- For sharded clusters, a ``shards`` field that includes the shard
and the size in bytes of the database on disk for each shard.

- A field named ``totalSize`` whose value is the sum of all the
``sizeOnDisk`` fields in bytes.

.. _listDatabases-behavior:

Behavior
--------

When :doc:`authentication </core/authentication>` is enabled:

.. note:: show dbs

.. note::

For :binary:`~bin.mongo` shell version 4.0.6+ connected to earlier
versions of MongoDB deployment (e.g. 3.6.10),
Expand Down Expand Up @@ -238,6 +215,7 @@ The following is an example of a :dbcommand:`listDatabases` result:
}
],
"totalSize" : 251658240,
"totalSizeMb" : 251,
"ok" : 1
}

Expand Down Expand Up @@ -290,6 +268,8 @@ name matches the specified :query:`regular expression <$regex>`:

db.adminCommand( { listDatabases: 1, filter: { "name": /^rep/ } } )

.. _listDatabases-sharded-clusters:

Sharded Clusters
~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -345,9 +325,66 @@ For example:
"ok" : 1
}

.. seealso::
.. seealso:: :doc:`/tutorial/use-database-commands`.

.. |checkmark| unicode:: U+2713

Output
------

:doc:`/tutorial/use-database-commands`.
.. data:: listDatabases.databases

*Type: Array*

.. |checkmark| unicode:: U+2713
Array of documents, each containing information on a single
database.

.. data:: listDatabases.databases.name

*Type: String*

Name of the database.

.. data:: listDatabases.databases.sizeOnDisk

*Type: Integer*

Total size of the database files on disk, expressed in bytes.

.. data:: listDatabases.databases.empty

*Type: Boolean*

Specifies whether the database is empty.

.. data:: listDatabases.databases.shards

*Type: Document*

Each element in the ``shards`` document consists of a field whose key
gives the name of a collection on that shard, and whose value
represents the collection's size in bytes.

``shards`` only appears in the output if ``nameOnly: false``.

See :ref:`Sharded Clusters <listDatabases-sharded-clusters>`
for details.

.. data:: listDatabases.totalSize

*Type: Integer*

Sum of all the ``sizeOnDisk`` fields in bytes.

.. data:: listDatabases.totalSizeMb

*Type: Integer*

Sum of all the ``sizeOnDisk`` fields, expressed in megabytes.

.. data:: listDatabases.ok

*Type: Integer*

Return value for the command. A value of ``1`` indicates
success.
60 changes: 60 additions & 0 deletions source/release-notes/5.0-compatibility.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,66 @@ operand expression ( ``{ }`` ):
An empty update results in no changes and no :term:`oplog` entry is
created (meaning that the operation is a no-op).

``listDatabases`` Output Changes
--------------------------------

Starting in MongoDB 5.0, output from the :dbcommand:`listDatabases`
command running against a :binary:`~bin.mongod` is more consistent with
output from :dbcommand:`listDatabases` running against a
:binary:`~bin.mongos`.

The following table shows the differences in data types for
:dbcommand:`listDatabases` output fields between MongoDB 5.0 and earlier
versions. Only fields which differ between 5.0 and earlier versions are
listed.

.. list-table::
:header-rows: 1
:widths: 30 30 30 30

* - Field

- Type in MongoDB 5.0

- Type in MongoDB 4.4 and earlier (``mongod``)

- Type in MongoDB 4.4 and earlier (``mongos``)

* - ``sizeOnDisk``

- integer

- double

- integer

* - ``totalSize``

- integer

- double

- integer

* - ``totalSizeMb``

- integer

- not present (see below)

- integer

The output from :dbcommand:`listDatabases` now includes the
``totalSizeMb`` field when run against either a :binary:`~bin.mongos` or
a :binary:`~bin.mongod`. In MongoDB 4.4 and earlier, ``totalSizeMb``
only appears when run against :binary:`~bin.mongos`. ``totalSizeMb`` is
the sum of the ``sizeOnDisk`` fields, expressed in megabytes.

When run against :binary:`~bin.mongos`, the ``shards`` field in the
:dbcommand:`listDatabases` output contains a field-value pair for each
collection on a particular shard. Size values in the ``shards`` field
are expressed as integers.

General Changes
---------------

Expand Down