Skip to content

Commit 1b8fd27

Browse files
committed
NH feedback
1 parent cdd710f commit 1b8fd27

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

source/includes/run-command.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
1+
//start-full-example
2+
import com.mongodb.MongoException
13
import com.mongodb.kotlin.client.MongoClient
24
import org.bson.Document
5+
import org.bson.BsonInt64
6+
import org.bson.json.JsonWriterSettings
7+
38

49
fun main() {
10+
// Replace the placeholder with your MongoDB deployment's connection string
11+
val uri = "<connection string uri>"
12+
13+
val mongoClient = MongoClient.create(uri)
14+
val database = mongoClient.getDatabase("sample_mflix")
15+
try {
16+
val command = Document("buildInfo", BsonInt64(1))
17+
val commandResult = database.runCommand(command)
18+
println(commandResult.toJson(JsonWriterSettings.builder().indent(true).build()))
19+
} catch (me: MongoException) {
20+
System.err.println("An error occurred: $me")
21+
}
22+
mongoClient.close()
23+
}
24+
//end-full-example
25+
26+
fun command_examples() {
527
//start-execute
6-
val commandToExplain = Document( "find", "restaurants")
28+
val commandToExplain = Document("find", "restaurants")
729
val explanation = database.runCommand(Document("explain", commandToExplain))
830
//end-execute
931

1032
//start-read-preference
1133
val command = Document("hello", 1)
12-
val commandReadPreference = Document( "readPreference", "secondary" )
34+
val commandReadPreference = Document("readPreference", "secondary")
1335

1436
val commandResult = database.runCommand(command, commandReadPreference)
1537
//end-read-preference
1638

1739
//start-build-info
18-
println( database.runCommand( Document( "buildInfo", 1 ) );
40+
println(database.runCommand(Document("buildInfo", 1));
1941
//end-build-info
2042
}

source/run-command.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Run a Command
1313
Overview
1414
--------
1515

16-
In this guide, you can learn how to run a database command with the
16+
In this guide, you can learn how to run a database command by using the
1717
{+driver-short+}. You can use database commands to perform a variety of
1818
administrative and diagnostic tasks, such as fetching server statistics,
1919
initializing a replica set, or running an aggregation pipeline.
@@ -125,8 +125,8 @@ The following code shows the general output format of the ``buildInfo`` command:
125125
.. io-code-block::
126126

127127
.. input:: /includes/run-command.kt
128-
:start-after: start-build-info
129-
:end-before: end-build-info
128+
:start-after: start-full-example
129+
:end-before: end-full-example
130130
:language: kotlin
131131
:dedent:
132132

@@ -135,11 +135,10 @@ The following code shows the general output format of the ``buildInfo`` command:
135135

136136
{
137137
version: '8.0.4',
138-
<other command results>
139-
storageEngines: [ ... ],
138+
...<other command results>...
140139
ok: 1,
141140
'$clusterTime': {
142-
clusterTime: Timestamp({ t: 1737993450, i: 32 }),
141+
clusterTime: Timestamp({ ... }),
143142
signature: {
144143
...
145144
}

0 commit comments

Comments
 (0)