@@ -15,26 +15,17 @@ Definition
15
15
16
16
.. method:: db.getSiblingDB(<database>)
17
17
18
-
19
18
.. list-table::
20
19
:header-rows: 1
21
20
:widths: 20 20 80
22
21
23
22
* - Parameter
24
-
25
23
- Type
26
-
27
24
- Description
28
25
29
26
* - ``database``
30
-
31
27
- string
32
-
33
28
- The name of a MongoDB database.
34
-
35
-
36
-
37
-
38
29
39
30
:returns: A database object.
40
31
@@ -47,33 +38,49 @@ Example
47
38
You can use :method:`db.getSiblingDB()` as an alternative to the ``use
48
39
<database>`` helper. This is particularly useful when writing scripts
49
40
using :binary:`~bin.mongosh` where the ``use`` helper is not
50
- available. Consider the following sequence of operations:
41
+ available.
42
+
43
+ Consider a MongoDB instance with two databases, ``users`` and
44
+ ``records``. The ``active`` collection is a part of the ``users``
45
+ database. The ``requests`` collection is a part of the ``records``
46
+ database.
47
+
48
+ Specify a Database
49
+ ~~~~~~~~~~~~~~~~~~
50
+
51
+ This operation sets the ``db`` object to point to the database named
52
+ ``users``, and then returns a :method:`document count
53
+ <db.collection.countDocuments>` for the ``active`` collection.
51
54
52
55
.. code-block:: javascript
53
56
54
57
db = db.getSiblingDB('users')
55
- db.active.count ()
58
+ db.active.countDocuments ()
56
59
57
- This operation sets the ``db`` object to point to the database named
58
- ``users``, and then returns a :doc:`count
59
- </reference/method/db.collection.count>` of the collection named
60
- ``active``. You can create multiple ``db`` objects, that refer to
61
- different databases, as in the following sequence of operations:
60
+ Use Multiple Databases
61
+ ~~~~~~~~~~~~~~~~~~~~~~
62
+
63
+ You can create multiple ``db`` objects, that refer to different
64
+ databases, as in the following sequence of operations:
62
65
63
66
.. code-block:: javascript
64
67
65
68
users = db.getSiblingDB('users')
66
69
records = db.getSiblingDB('records')
67
70
68
- users.active.count ()
71
+ users.active.countDocuments ()
69
72
users.active.findOne()
70
73
71
- records.requests.count ()
74
+ records.requests.countDocuments ()
72
75
records.requests.findOne()
73
76
74
- This operation creates two ``db`` objects referring to different
75
- databases (i.e. ``users`` and ``records``) and then returns a
76
- :doc:`count </reference/method/db.collection.count>` and an
77
- :doc:`example document </reference/method/db.collection.findOne>` from
78
- one collection in that database (i.e. ``active`` and ``requests``
79
- respectively.)
77
+ This operation creates two ``db`` objects. Each ``db`` object refers to
78
+ a different database, ``users`` or ``records``.
79
+
80
+ For each database, the query returns:
81
+
82
+ - a :method:`document count <db.collection.countDocuments>`, and
83
+ - an :method:`example document <db.collection.findOne>`
84
+
85
+ from a collection in that database.
86
+
0 commit comments