Skip to content

Commit dce7f0b

Browse files
author
Kay Kim
committed
DOCS-12141: listDatabases authorizedDatabases
1 parent 8d8185e commit dce7f0b

File tree

5 files changed

+97
-32
lines changed

5 files changed

+97
-32
lines changed

source/includes/apiargs-dbcommand-listDatabases-field.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ description: |
3636
3737
.. versionadded:: 3.6
3838
39+
interface: dbcommand
40+
operation: listDatabases
41+
arg_name: field
42+
optional: true
43+
---
44+
name: authorizedDatabases
45+
type: boolean
46+
description: |
47+
48+
A flag that determines which databases are returned based on the
49+
user privileges when access control is enabled.
50+
51+
.. include:: /includes/extracts/listDatabases-auth-privileges.rst
52+
53+
For more information, see :ref:`listDatabases-behavior`.
54+
55+
.. versionadded:: 4.0.5
56+
3957
interface: dbcommand
4058
operation: listDatabases
4159
arg_name: field
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
ref: listDatabases-auth-privileges
2+
content: |
3+
4+
- If ``authorizedDatabases`` is unspecified, and
5+
6+
- If the user has :authaction:`listDatabases` action on the
7+
cluster resource, :dbcommand:`listDatabases` command returns all
8+
databases.
9+
10+
- If the user does not have :authaction:`listDatabases` action on
11+
the cluster, :dbcommand:`listDatabases` command returns only the
12+
databases for which the user has the :authaction:`find` action
13+
on the database resource (and not the collection resource).
14+
15+
- If ``authorizedDatabases`` is ``true``, :dbcommand:`listDatabases`
16+
command returns only the databases for which the user has the
17+
:authaction:`find` action on the database resource (and not the
18+
collection resource).
19+
20+
21+
- If ``authorizedDatabases`` is ``false``, and
22+
23+
- If the user has :authaction:`listDatabases` action on the
24+
cluster, :dbcommand:`listDatabases` command returns all databases
25+
26+
- If the user does not have :authaction:`listDatabases` action on
27+
the cluster, :dbcommand:`listDatabases` command errors with
28+
insufficient permissions.
29+
30+
---
31+
ref: listDatabases-auth-4.0.0-4.0.4
32+
content: |
33+
For MongoDB 4.0.0-4.0.4:
34+
If the user does not have the :authaction:`listDatabases`
35+
privilege action, users can run the :dbcommand:`listDatabases`
36+
command to return a list of databases for which the user has the
37+
:authaction:`find` action privilege.
38+
---
39+
ref: listDatabases-auth-4.0.5
40+
content: |
41+
For MongoDB 4.0.5+:
42+
If the user does not have the :authaction:`listDatabases`
43+
privilege action, users can run the :dbcommand:`listDatabases`
44+
command to return a list of databases for which the user has the
45+
:authaction:`find` action privilege if the command is run with
46+
``authorizedDatabases`` option unspecified or set to ``true``.
47+
48+
...

source/reference/built-in-roles.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,9 @@ Every database includes the following client roles:
6161
- :authaction:`listIndexes`
6262
- :authaction:`listCollections`
6363

64-
.. versionchanged:: 4.0
65-
66-
If the user does not have the :authaction:`listDatabases`
67-
privilege action, users can run the :dbcommand:`listDatabases`
68-
command to return a list of databases for which the user has the
69-
:authaction:`find` action privilege.
64+
.. include:: /includes/extracts/listDatabases-auth-4.0.0-4.0.4.rst
65+
66+
.. include:: /includes/extracts/listDatabases-auth-4.0.5.rst
7067

7168
.. authrole:: readWrite
7269

source/reference/command/listDatabases.txt

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ Definition
3030
The :dbcommand:`listDatabases` command can take the following
3131
optional fields:
3232

33-
.. versionchanged:: 4.0
34-
3533
.. include:: /includes/apiargs/dbcommand-listDatabases-field.rst
3634

3735
Output
@@ -55,24 +53,33 @@ Output
5553
- A field named ``totalSize`` whose value is the sum of all the
5654
``sizeOnDisk`` fields in bytes.
5755

56+
.. _listDatabases-behavior:
57+
5858
Behavior
5959
--------
6060

61-
.. versionchanged:: 4.0
61+
When :doc:`authentication </core/authentication>` is enabled:
62+
63+
- For MongoDB 4.0.5+:
64+
The :dbcommand:`listDatabases` command returns different values
65+
based on the privileges assigned to the user who
66+
executes the command and the ``authorizedDatabases`` command option:
6267

63-
When :doc:`authentication </core/authentication>` is enabled, the
64-
:dbcommand:`listDatabases` command returns different values based on
65-
the :doc:`privilege actions </reference/privilege-actions/>`
66-
assigned to the user who executes the command.
68+
.. include:: /includes/extracts/listDatabases-auth-privileges.rst
6769

68-
- If the user has the :authaction:`listDatabases` privilege action,
69-
the :dbcommand:`listDatabases` command returns a list of all
70-
existing databases.
70+
- For MongoDB 4.0.0-4.0.4:
71+
The :dbcommand:`listDatabases` command returns different values
72+
based on the privileges assigned to the user who
73+
executes the command.
74+
75+
- If the user has the :authaction:`listDatabases` privilege action
76+
on the cluster, the :dbcommand:`listDatabases` command returns a
77+
list of all existing databases.
7178

7279
- If the user does not have the :authaction:`listDatabases`
73-
privilege action, the :dbcommand:`listDatabases` command only
74-
returns a list of databases for which the user has the
75-
:authaction:`find` action privilege.
80+
privilege action on the cluster, the :dbcommand:`listDatabases`
81+
command only returns a list of databases for which the user has
82+
the :authaction:`find` action.
7683

7784
Examples
7885
--------
@@ -217,3 +224,5 @@ For example:
217224
}
218225

219226
.. seealso:: :doc:`/tutorial/use-database-commands`.
227+
228+
.. |checkmark| unicode:: U+2713

source/reference/privilege-actions.txt

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ Query and Write Actions
6464
and :dbcommand:`renameCollection` commands and the
6565
:method:`db.collection.renameCollection()` helper method.
6666

67-
.. versionchanged:: 4.0
68-
69-
If a user running the :dbcommand:`listDatabases` command does not
70-
have the :authaction:`listDatabases` privilege action, the command
71-
returns a list of databases for which the user has the
72-
:authaction:`find` privilege action.
67+
.. include:: /includes/extracts/listDatabases-auth-4.0.0-4.0.4.rst
68+
69+
.. include:: /includes/extracts/listDatabases-auth-4.0.5.rst
7370

7471
Apply this action to database or collection resources.
7572

@@ -711,13 +708,9 @@ Diagnostic Actions
711708
User can perform the :dbcommand:`listDatabases` command. Apply this
712709
action to the ``cluster`` resource.
713710

714-
.. versionchanged:: 4.0
715-
716-
If a user running the :dbcommand:`listDatabases` command does
717-
not have the :authaction:`listDatabases` privilege action, the
718-
:dbcommand:`listDatabases` command only returns a list of
719-
databases for which the user has the :authaction:`find` action
720-
privilege.
711+
.. include:: /includes/extracts/listDatabases-auth-4.0.0-4.0.4.rst
712+
713+
.. include:: /includes/extracts/listDatabases-auth-4.0.5.rst
721714

722715
.. authaction:: listCollections
723716

0 commit comments

Comments
 (0)