Skip to content

Commit 71f642b

Browse files
committed
NR PR fixes 1
1 parent 7c0ec5b commit 71f642b

File tree

2 files changed

+66
-131
lines changed

2 files changed

+66
-131
lines changed

source/get-started/pojo-qs.txt

Lines changed: 64 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ Quick Start (POJO Examples)
1010
:depth: 1
1111
:class: singlecol
1212

13-
This guide follows from the :ref:`Quick Start guide <javars-quickstart>`, but uses Plain
14-
Old Java Objects, or POJOs, to model documents.
13+
This guide follows from the :ref:`Quick Start guide
14+
<javars-quickstart>` but uses Plain Old Java Objects, or POJOs, to
15+
model documents.
1516

1617
The code examples in this guide come from the `PojoQuickTour.java
1718
<{+driver-source-gh+}/blob/master/driver-reactive-streams/src/examples/reactivestreams/tour/PojoQuickTour.java>`__
@@ -54,101 +55,23 @@ this guide:
5455
import static org.bson.codecs.configuration.CodecRegistries.fromProviders;
5556
import static org.bson.codecs.configuration.CodecRegistries.fromRegistries;
5657

57-
- POJO class definitions. The full code is available on GitHub
58-
for the ``Person`` and ``Address`` POJOs. The following code
59-
demonstrates the main implementation details:
60-
61-
.. code-block:: java
62-
63-
public final class Person {
64-
private ObjectId id;
65-
private String name;
66-
private int age;
67-
private Address address;
68-
69-
public Person() {
70-
}
71-
72-
public ObjectId getId() {
73-
return id;
74-
}
75-
76-
public void setId(final ObjectId id) {
77-
this.id = id;
78-
}
79-
80-
public String getName() {
81-
return name;
82-
}
83-
84-
public void setName(final String name) {
85-
this.name = name;
86-
}
87-
88-
public int getAge() {
89-
return age;
90-
}
91-
92-
public void setAge(final int age) {
93-
this.age = age;
94-
}
95-
96-
public Address getAddress() {
97-
return address;
98-
}
99-
100-
public void setAddress(final Address address) {
101-
this.address = address;
102-
}
103-
104-
// Rest of implementation
105-
}
106-
107-
public final class Address {
108-
private String street;
109-
private String city;
110-
private String zip;
111-
112-
public Address() {
113-
}
114-
115-
public String getStreet() {
116-
return street;
117-
}
118-
119-
public void setStreet(final String street) {
120-
this.street = street;
121-
}
122-
123-
public String getCity() {
124-
return city;
125-
}
126-
127-
public void setCity(final String city) {
128-
this.city = city;
129-
}
130-
131-
public String getZip() {
132-
return zip;
133-
}
134-
135-
public void setZip(final String zip) {
136-
this.zip = zip;
137-
}
138-
139-
// Rest of implementation
140-
}
58+
- POJO class definitions. Copy the full code for the ``Person`` and
59+
``Address`` POJOs from the driver source repository on
60+
GitHub:
61+
62+
- `Person class <{+driver-source-gh+}/blob/master/driver-reactive-streams/src/examples/reactivestreams/tour/Person.java>`__
63+
- `Address class <{+driver-source-gh+}/blob/master/driver-reactive-streams/src/examples/reactivestreams/tour/Address.java>`__
14164

14265
Creating a Custom CodecRegistry
14366
-------------------------------
14467

14568
Before you can use a POJO with the driver, you need to configure the
146-
``CodecRegistry`` to include a codec to handle the translation to and
69+
``CodecRegistry`` to include a codec that handles the translation to and
14770
from BSON for your POJOs. The simplest way to do that is to use
14871
the ``PojoCodecProvider.builder()`` method to create and configure a
14972
``CodecProvider``.
15073

151-
The following example combines the default codec registry, with
74+
The following example combines the default codec registry with
15275
the ``PojoCodecProvider`` configured to automatically create POJO
15376
``Codec`` instances:
15477

@@ -174,24 +97,24 @@ use:
17497

17598
- Set it when instantiating a ``MongoClient`` object:
17699

177-
.. code-block:: java
178-
179-
MongoClientSettings settings = MongoClientSettings.builder()
180-
.codecRegistry(pojoCodecRegistry)
181-
.build();
182-
MongoClient mongoClient = MongoClients.create(settings);
100+
.. code-block:: java
101+
102+
MongoClientSettings settings = MongoClientSettings.builder()
103+
.codecRegistry(pojoCodecRegistry)
104+
.build();
105+
MongoClient mongoClient = MongoClients.create(settings);
183106

184107
- Use an alternative ``CodecRegistry`` with a ``MongoDatabase``:
185108

186-
.. code-block:: java
187-
188-
database = database.withCodecRegistry(pojoCodecRegistry);
109+
.. code-block:: java
110+
111+
database = database.withCodecRegistry(pojoCodecRegistry);
189112

190113
- Use an alternative ``CodecRegistry`` with a ``MongoCollection``:
191114

192-
.. code-block:: java
193-
194-
collection = collection.withCodecRegistry(pojoCodecRegistry);
115+
.. code-block:: java
116+
117+
collection = collection.withCodecRegistry(pojoCodecRegistry);
195118

196119
Inserting a POJO into MongoDB
197120
-----------------------------
@@ -210,6 +133,8 @@ Before you can insert a POJO into MongoDB, create a
210133
Insert a Person Instance
211134
~~~~~~~~~~~~~~~~~~~~~~~~
212135

136+
.. _javars-pojo-insertone:
137+
213138
To insert a ``Person`` into the collection, use the collection's
214139
``insertOne()`` method:
215140

@@ -222,7 +147,8 @@ Insert Multiple Person Instances
222147
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
223148

224149
To insert multiple ``Person`` instances, you can use the collection's
225-
``insertMany()`` method, which takes a list of ``Person`` instances.
150+
``insertMany()`` method, which takes a list of ``Person`` instances as a
151+
parameter.
226152

227153
The following example will add multiple ``Person`` instances into the
228154
collection:
@@ -244,18 +170,22 @@ To query the collection, you can use the ``find()`` method.
244170
The following example prints all the ``Person`` instances in the
245171
collection:
246172

247-
.. code-block:: java
173+
.. io-code-block::
174+
:copyable: true
248175

249-
collection.find().subscribe(new PrintToStringSubscriber<>());
176+
.. input::
177+
:language: java
250178

251-
The example prints the following result:
179+
collection.find().subscribe(new PrintToStringSubscriber<>());
252180

253-
.. code-block:: none
181+
.. output::
182+
:language: none
183+
:visible: false
254184

255-
Person{id='...', name='Ada Byron', age=20, address=Address{street='St James Square', city='London', zip='W1'}}
256-
Person{id='...', name='Charles Babbage', age=45, address=Address{street='5 Devonshire Street', city='London', zip='W11'}}
257-
Person{id='...', name='Alan Turing', age=28, address=Address{street='Bletchley Hall', city='Bletchley Park', zip='MK12'}}
258-
Person{id='...', name='Timothy Berners-Lee', age=61, address=Address{street='Colehill', city='Wimborne', zip='null'}}
185+
Person{id='...', name='Ada Byron', age=20, address=Address{street='St James Square', city='London', zip='W1'}}
186+
Person{id='...', name='Charles Babbage', age=45, address=Address{street='5 Devonshire Street', city='London', zip='W11'}}
187+
Person{id='...', name='Alan Turing', age=28, address=Address{street='Bletchley Hall', city='Bletchley Park', zip='MK12'}}
188+
Person{id='...', name='Timothy Berners-Lee', age=61, address=Address{street='Colehill', city='Wimborne', zip='null'}}
259189

260190
Specify a Query Filter
261191
----------------------
@@ -266,28 +196,32 @@ filter objects, the driver provides ``Filters`` helper methods.
266196

267197
.. important::
268198

269-
When querying POJOs you *must* query against the document field name
199+
When querying POJOs, you *must* query against the document field name
270200
and not the POJO property name. By default, they are the same but it
271201
is possible to change how POJO property names are mapped.
272202

273203
Get A Single Person That Matches a Filter
274204
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
275205

276-
For example, to find the first ``Person`` in the database that lives in
277-
``Wimborne``, pass an ``eq()`` filter object to specify the equality
278-
condition:
206+
The following example finds the first ``Person`` in the database that
207+
has an ``address.city`` value of ``Wimborne`` by passing an ``eq()``
208+
filter object to specify the equality condition:
279209

280-
.. code-block:: java
210+
.. io-code-block::
211+
:copyable: true
281212

282-
collection.find(eq("address.city", "Wimborne"))
283-
.first()
284-
.subscribe(new PrintToStringSubscriber<>());
213+
.. input::
214+
:language: java
285215

286-
The example prints one document:
216+
collection.find(eq("address.city", "Wimborne"))
217+
.first()
218+
.subscribe(new PrintToStringSubscriber<>());
287219

288-
.. code-block:: none
220+
.. output::
221+
:language: none
222+
:visible: false
289223

290-
Person{id='591dbc2550852fa685b3ad1a', name='Timothy Berners-Lee', age=61, address=Address{street='Colehill', city='Wimborne', zip='null'}}
224+
Person{id='591dbc2550852fa685b3ad1a', name='Timothy Berners-Lee', age=61, address=Address{street='Colehill', city='Wimborne', zip='null'}}
291225

292226
Get All Person Instances That Match a Filter
293227
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -305,12 +239,12 @@ Update Documents
305239
To update documents in a collection, you can use the collection's
306240
``updateOne()`` and ``updateMany()`` methods.
307241

308-
Pass the following components to the methods:
242+
Pass the following parameters to the methods:
309243

310244
- Filter object to determine the document or documents to update. To
311245
specify an empty filter and match all ``Person`` instances, use an
312246
empty ``Document`` object.
313-
- An update document that specifies the modifications. To view a list of
247+
- Update document that specifies the modifications. To view a list of
314248
the available operators, see :manual:`Update Operators
315249
</reference/operator/update/>` in the Server manual.
316250

@@ -350,11 +284,12 @@ that have a ``zip`` value:
350284
Replace a Single Person
351285
~~~~~~~~~~~~~~~~~~~~~~~
352286

353-
Another method to change an existing ``Person`` instance is to use
287+
Another way to change an existing ``Person`` instance is to use
354288
the ``replaceOne()`` method.
355289

356290
The following example replaces a ``Person`` named ``"Ada Lovelace"``
357-
with the original ``Person`` instance:
291+
with the ``Person`` instance referenced by the ``ada`` variable in the
292+
:ref:`preceding insertOne example <javars-pojo-insertone>`:
358293

359294
.. code-block:: java
360295

@@ -378,10 +313,10 @@ Delete a Single Person That Matches a Filter
378313
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
379314

380315
To delete a single ``Person`` that matches a filter, use the
381-
``deleteOne()`` method:
316+
``deleteOne()`` method.
382317

383-
The following example deletes one ``Person`` who lives in
384-
the city ``Wimborne``:
318+
The following example deletes one ``Person`` that has an
319+
``address.city`` value of ``Wimborne``:
385320

386321
.. code-block:: java
387322

@@ -394,8 +329,8 @@ Delete All Person Instances That Match a Filter
394329
To delete multiple ``Person`` instances that match a filter, use the
395330
``deleteMany()`` method.
396331

397-
The following example deletes all ``Person`` instances that live in
398-
the city ``London``:
332+
The following example deletes all ``Person`` instances that have an
333+
``address.city`` value of ``London``:
399334

400335
.. code-block:: java
401336

source/get-started/quickstart.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ Update Documents
430430
To update documents in a collection, you can use the collection's
431431
``updateOne()`` and ``updateMany()`` methods.
432432

433-
Pass the following components to the methods:
433+
Pass the following parameters to the methods:
434434

435435
- Filter object to determine the document or documents to update. To
436436
facilitate creating filter objects, the driver provides
437437
``Filters`` helper methods. To specify an empty filter and match all
438438
documents in the collection, use an empty ``Document`` object.
439-
- An update document that specifies the modifications. To view a list of
439+
- Update document that specifies the modifications. To view a list of
440440
the available operators, see :manual:`Update Operators
441441
</reference/operator/update/>` in the Server manual.
442442

0 commit comments

Comments
 (0)