Skip to content

Commit 6bf63b1

Browse files
committed
add output
1 parent 1d1f1a6 commit 6bf63b1

File tree

2 files changed

+59
-56
lines changed

2 files changed

+59
-56
lines changed

source/includes/run-command.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import com.mongodb.kotlin.client.MongoClient
2+
import org.bson.Document
3+
4+
fun main() {
5+
//start-execute
6+
val command = {
7+
find: "restaurants",
8+
filter: { cuisine: "Italian" },
9+
projection: { name: 1, rating: 1, address: 1 },
10+
sort: { name: 1 },
11+
limit: 5
12+
}
13+
val commandResult = database.runCommand(command)
14+
//end-execute
15+
16+
//start-read-preference
17+
val command = { "hello": 1 }
18+
val commandReadPreference = { readPreference: "secondary" }
19+
20+
val commandResult = database.runCommand(command, readPreference)
21+
//end-read-preference
22+
}

source/run-command.txt

Lines changed: 37 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,12 @@ The following code shows how you can use the ``runCommand()``
4040
method to run the ``find`` command, which returns information about
4141
the current member's role in the replica set, on a database:
4242

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:
5349

5450
For a full list of database commands and corresponding parameters, see
5551
the :manual:`Database Commands </reference/command/>` guide.
@@ -64,12 +60,12 @@ including a ``readPreference`` parameter. The following example shows how to
6460
specify a read preference and pass it as an option to the ``runCommand()``
6561
method:
6662

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:
7369

7470
For more information on read preference options, see :manual:`Read Preference
7571
</core/read-preference/>` in the Server manual.
@@ -124,48 +120,33 @@ with the following fields:
124120
Example
125121
-------
126122

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:
130124

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+
}
163148

164-
.. note::
165149

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.
169150

170151
.. _addl-info-runcommand:
171152

@@ -175,7 +156,7 @@ Additional Information
175156
For more information about the concepts in this guide, see the following documentation:
176157

177158
- 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>`__
179160
- Database
180161
- :manual:`Database Commands </reference/command/>`
181162
- :manual:`hello Command </reference/command/hello/>`

0 commit comments

Comments
 (0)