@@ -40,16 +40,12 @@ The following code shows how you can use the ``runCommand()``
40
40
method to run the ``find`` command, which returns information about
41
41
the current member's role in the replica set, on a database:
42
42
43
- .. code-block:: javascript
44
-
45
- val command = {
46
- find: "restaurants",
47
- filter: { rating: { $gte: 9 }, cuisine: "italian" },
48
- projection: { name: 1, rating: 1, address: 1 },
49
- sort: { name: 1 },
50
- limit: 5
51
- }
52
- val commandResult = database.runCommand(command)
43
+ .. literalinclude:: /includes/run-command.kt
44
+ :start-after: start-execute
45
+ :end-before: end-execute
46
+ :language: kotlin
47
+ :copyable:
48
+ :dedent:
53
49
54
50
For a full list of database commands and corresponding parameters, see
55
51
the :manual:`Database Commands </reference/command/>` guide.
@@ -64,12 +60,12 @@ including a ``readPreference`` parameter. The following example shows how to
64
60
specify a read preference and pass it as an option to the ``runCommand()``
65
61
method:
66
62
67
- .. code-block :: javascript
68
-
69
- val command = { "hello": 1 }
70
- val commandReadPreference = { readPreference: "secondary" }
71
-
72
- val commandResult = database.runCommand(command, readPreference)
63
+ .. literalinclude :: /includes/run-command.kt
64
+ :start-after: start-read-preference
65
+ :end-before: end-read-preference
66
+ :language: kotlin
67
+ :copyable:
68
+ :dedent:
73
69
74
70
For more information on read preference options, see :manual:`Read Preference
75
71
</core/read-preference/>` in the Server manual.
@@ -124,48 +120,33 @@ with the following fields:
124
120
Example
125
121
-------
126
122
127
- The following code shows how you can use the ``runCursorCommand()`` method to
128
- run the ``checkMetadataConsistency`` command on the ``testDB`` database
129
- and iterate through the results:
123
+ The following code shows the general output format of the ``buildInfo`` command:
130
124
131
- .. literalinclude:: /code-snippets/crud/runCommand.js
132
- :language: javascript
133
- :dedent:
134
- :start-after: start-runcommand
135
- :end-before: end-runcommand
136
-
137
- Output
138
- ~~~~~~
139
-
140
- The output contains the contents of the cursor object. The documents
141
- describe any metadata inconsistencies in the database:
142
-
143
- .. code-block:: javascript
144
-
145
- {
146
- type: ...,
147
- description: ...,
148
- details: {
149
- namespace: ...,
150
- info: ...
151
- }
152
- }
153
- {
154
- type: ...,
155
- description: ...,
156
- details: {
157
- namespace: ...,
158
- collectionUUID: ...,
159
- maxKeyObj: ...,
160
- ...
161
- }
162
- }
125
+ .. io-code-block::
126
+
127
+ .. input:: /includes/aggregation/aggregation.kt
128
+ :language: kotlin
129
+
130
+ db.runCommand( { buildInfo: 1 } );
131
+
132
+ .. output::
133
+ :visible: false
134
+
135
+ {
136
+ version: '8.0.4',
137
+ <other command results>
138
+ storageEngines: [ ... ],
139
+ ok: 1,
140
+ '$clusterTime': {
141
+ clusterTime: Timestamp({ t: 1737993450, i: 32 }),
142
+ signature: {
143
+ ...
144
+ }
145
+ },
146
+ operationTime: Timestamp({ ... })
147
+ }
163
148
164
- .. note::
165
149
166
- If you store the command response in a cursor, you see only the
167
- command result documents when you access the contents of the cursor. You won't
168
- see the ``ok``, ``operationTime``, and ``$clusterTime`` fields.
169
150
170
151
.. _addl-info-runcommand:
171
152
@@ -175,7 +156,7 @@ Additional Information
175
156
For more information about the concepts in this guide, see the following documentation:
176
157
177
158
- Kotlin API
178
- - :driver: `runCommand() <{+api+}/apidocs/mongodb-driver-kotlin-sync/mongodb-driver-kotlin-sync/ com.mongodb.kotlin.client/-mongo-database/run-command.html>`
159
+ - `runCommand() <{+api+}/com.mongodb.kotlin.client/-mongo-database/run-command.html>`__
179
160
- Database
180
161
- :manual:`Database Commands </reference/command/>`
181
162
- :manual:`hello Command </reference/command/hello/>`
0 commit comments