Skip to content

Commit 4a07841

Browse files
committed
Address further technical feedback
1 parent 638a476 commit 4a07841

File tree

2 files changed

+48
-22
lines changed

2 files changed

+48
-22
lines changed

source/includes/usage-examples/index-code-examples.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ public static void main(String[] args) {
3434
MongoCollection<Document> collection = database.getCollection("movies");
3535

3636
// start-single-field
37-
Publisher<String> result = collection.createIndex(Indexes.ascending("<field name>"));
38-
Mono.from(result).block();
37+
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name>"));
38+
Mono.from(publisher).block();
3939
// end-single-field
4040

4141
// start-compound
42-
Publisher<String> result = collection.createIndex(Indexes.ascending("<field name 1>", "<field name 2>"));
43-
Mono.from(result).block();
42+
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name 1>", "<field name 2>"));
43+
Mono.from(publisher).block();
4444
// end-compound
4545

4646
// start-multikey
47-
Publisher<String> result = collection.createIndex(Indexes.ascending("<array field name>"));
48-
Mono.from(result).block();
47+
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<array field name>"));
48+
Mono.from(publisher).block();
4949
// end-multikey
5050

5151
// start-search-create
5252
Document index = new Document("mappings", new Document("dynamic", true));
53-
Publisher<String> result = collection.createSearchIndex("<index name>", index);
54-
Mono.from(result).block();
53+
Publisher<String> publisher = collection.createSearchIndex("<index name>", index);
54+
Mono.from(publisher).block();
5555
// end-search-create
5656

5757
// start-search-list
@@ -64,34 +64,34 @@ public static void main(String[] args) {
6464

6565
// start-search-update
6666
Document newIndex = new Document("mappings", new Document("dynamic", true));
67-
Publisher<Void> result = collection.updateSearchIndex("<index name>", newIndex);
68-
Mono.from(result).block();
67+
Publisher<Void> publisher = collection.updateSearchIndex("<index name>", newIndex);
68+
Mono.from(publisher).block();
6969
// end-search-update
7070

7171
// start-search-delete
72-
Publisher<Void> result = collection.dropIndex("<index name>");
73-
Mono.from(result).block();
72+
Publisher<Void> publisher = collection.dropIndex("<index name>");
73+
Mono.from(publisher).block();
7474
// end-search-delete
7575

7676
// start-text
77-
Publisher<String> result = collection.createIndex(Indexes.text("<field name>"));
78-
Mono.from(result).block();
77+
Publisher<String> publisher = collection.createIndex(Indexes.text("<field name>"));
78+
Mono.from(publisher).block();
7979
// end-text
8080

8181
// start-geo
82-
Publisher<String> result = collection.createIndex(Indexes.geo2dsphere("<GeoJSON object field>"));
83-
Mono.from(result).block();
82+
Publisher<String> publisher = collection.createIndex(Indexes.geo2dsphere("<GeoJSON object field>"));
83+
Mono.from(publisher).block();
8484
// end-geo
8585

8686
// start-unique
8787
IndexOptions indexOptions = new IndexOptions().unique(true);
88-
Publisher<String> result = collection.createIndex(Indexes.ascending("<field name>"), indexOptions);
89-
Mono.from(result).block();
88+
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name>"), indexOptions);
89+
Mono.from(publisher).block();
9090
// end-unique
9191

9292
// start-wildcard
93-
Publisher<String> result = collection.createIndex(Indexes.ascending("$**"));
94-
Mono.from(result).block();
93+
Publisher<String> publisher = collection.createIndex(Indexes.ascending("$**"));
94+
Mono.from(publisher).block();
9595
// end-wildcard
9696

9797
// start-clustered
@@ -109,8 +109,8 @@ public static void main(String[] args) {
109109
// end-clustered
110110

111111
// start-remove
112-
Publisher<Void> result = collection.dropIndex("<index name>");
113-
Mono.from(result).block();
112+
Publisher<Void> publisher = collection.dropIndex("<index name>");
113+
Mono.from(publisher).block();
114114
// end-remove
115115
}
116116
}

source/indexes.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,32 @@ To use an example from this page, copy the code example into the
3535
Be sure to replace all placeholders in the code examples, such as ``<connection string URI>``, with
3636
the relevant values for your MongoDB deployment.
3737

38+
Project Reactor Implementation
39+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40+
41+
This guide uses the {+pr+} library to consume ``Publisher`` instances returned
42+
by the {+driver-short+} methods. To learn more about the {+pr+} library
43+
and how to use it, see `Getting Started <https://projectreactor.io/docs/core/release/reference/#getting-started>`__
44+
in the Reactor documentation.
45+
46+
There are also other ways to consume ``Publisher`` instances. You can use one of many alternative libraries such as
47+
`RxJava <https://github.com/ReactiveX/RxJava>`__ or call ``Publisher.subscribe()`` directly and pass your own
48+
implementation of a ``Subscriber``.
49+
50+
This guide uses the ``Mono.block()`` method from Reactor to subscribe to a ``Publisher`` and block the current
51+
thread until the ``Publisher`` reaches its terminal state. To learn more about the Reactive Streams initiative, see `Reactive Streams <https://www.reactive-streams.org/>`__.
52+
53+
.. important:: Publishers Returned are Cold
54+
55+
All ``Publisher`` instances returned by the {+driver-short+} methods are cold,
56+
which means that the corresponding operation does not happen unless you
57+
subscribe to the returned ``Publisher``. We recommend only subscribing to
58+
the returned ``Publisher`` once, because subscribing more than once can lead
59+
to errors.
60+
61+
Sample Application
62+
~~~~~~~~~~~~~~~~~~
63+
3864
.. _java-rs-index-sample:
3965

4066
.. include:: /includes/usage-examples/sample-index-app-intro.rst

0 commit comments

Comments
 (0)