Skip to content

Commit 50f67a4

Browse files
DOCSP-39732 Run a command standardization (#77)
1 parent 32dcdcd commit 50f67a4

File tree

4 files changed

+76
-71
lines changed

4 files changed

+76
-71
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Document command = new Document("ping", 1);
2+
3+
Publisher<Document> commandPublisher = database.runCommand(command);
4+
Document result = Mono.from(commandPublisher).block();
5+
System.out.println(result);

source/write-data-to-mongo.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Write Data to MongoDB
2929
/write/bulk-writes
3030
/write/store-large-docs
3131
/write/write-concern
32-
/write/command
32+
/write/run-command
3333

3434
Overview
3535
--------

source/write/command.txt

Lines changed: 0 additions & 70 deletions
This file was deleted.

source/write/run-command.txt

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. _java-rs-run-command:
2+
3+
======================
4+
Run a Database Command
5+
======================
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 2
11+
:class: singlecol
12+
13+
.. facet::
14+
:name: genre
15+
:values: reference
16+
17+
.. meta::
18+
:keywords: database operation, code example
19+
20+
Overview
21+
--------
22+
23+
In this guide, you can learn how to run a database command with the
24+
{+driver-short+}. You can use database commands to perform a variety of administrative and
25+
diagnostic tasks, such as fetching server statistics, initializing a replica
26+
set, or running an aggregation pipeline.
27+
28+
.. tip:: Prefer Driver Methods Over Database Commands
29+
30+
The driver provides methods for many database commands. We recommend
31+
using driver methods instead of executing database commands when possible.
32+
33+
To perform administrative tasks, use the :mdb-shell:`MongoDB Shell </>` instead of the
34+
{+driver-short+}. Calling the MongoDB Shell :manual:`db.runCommand()
35+
</reference/method/db.runCommand/>` method is the preferred method to issue
36+
database commands, as it provides a consistent interface between the shell
37+
and drivers.
38+
39+
.. include:: includes/reactor-note.rst
40+
41+
Run a Command
42+
-------------
43+
44+
To run a database command, specify the command in a document, and pass the
45+
document to the ``runCommand()`` method. The following code calls the
46+
``runCommand()`` method on a database to run the ``ping`` command, which is a
47+
no-op command used to test if a server is responsive.
48+
49+
.. io-code-block::
50+
51+
.. input:: /includes/write/run-command.java
52+
:language: java
53+
:emphasize-lines: 1, 3
54+
55+
.. output::
56+
:visible: false
57+
58+
Document{{ok=1}}
59+
60+
Additional Information
61+
----------------------
62+
63+
To see a full list of database commands and their available parameters, see :manual:`Database
64+
Commands </reference/command>` in the {+mdb-server+} manual.
65+
66+
API Documentation
67+
~~~~~~~~~~~~~~~~~
68+
69+
To learn more about the ``runCommand()`` method, see the
70+
`runCommand() API documentation <{+api+}/mongodb-driver-reactivestreams/com/mongodb/reactivestreams/client/MongoDatabase.html#runCommand(org.bson.conversions.Bson)>`__.

0 commit comments

Comments
 (0)