@@ -108,7 +108,7 @@ make sure to follow the following guidelines:
108108- If you include public getter or setter methods using the
109109 `JavaBean naming conventions <https://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html>`__
110110 in your POJO, the driver calls them when serializing or deserializing data.
111- If you omit the getter or setter methods for a public property field, the
111+ If you omit the getter or setter methods for a public property field, the
112112 driver accesses or assigns them directly.
113113
114114Configure the Driver for POJOs
@@ -124,8 +124,9 @@ To set up the driver to store and retrieve POJOs, we need to specify:
124124 instance that contains the codec provider and other related information.
125125- A ``MongoClient``, ``MongoDatabase``, or ``MongoCollection`` instance
126126 configured to use the ``CodecRegistry``.
127- - A ``MongoCollection`` instance configured to cast to your POJO document
128- class.
127+ - A ``MongoCollection`` instance created with the POJO document class
128+ bound to the :java-docs:`TDocument </apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html>`__
129+ generic type.
129130
130131Follow the steps below to see how to perform each of the configuration
131132requirements:
@@ -187,8 +188,9 @@ requirements:
187188 // ...
188189 }
189190
190- #. Configure your ``MongoCollection`` instance to cast to your POJO class when
191- retrieving documents:
191+ #. Pass your POJO class to your call to ``getCollection()`` as the
192+ document class parameter and specify it as the type argument of your
193+ ``MongoCollection`` instance as follows:
192194
193195 .. code-block:: java
194196
@@ -199,9 +201,8 @@ Once you have configured the ``MongoCollection`` instance above, you can:
199201- save an instance of the POJO to the collection
200202- retrieve instances of the POJO from a query on the collection
201203
202- The code below shows you how you can set data in an instance of a ``Flower``,
203- save it in the collection, and retrieve the data in a ``List`` of ``Flower``
204- objects.
204+ The code below shows you how you can insert an instance of ``Flower`` into
205+ the collection and then retrieve it as a ``List`` of your POJO class objects:
205206
206207.. code-block:: java
207208
@@ -211,17 +212,8 @@ objects.
211212 collection.insertOne(flower);
212213
213214 // return all documents in the collection
214- List<Flower> flowers = new ArrayList<Flower>();
215-
216- MongoCursor<Flower> cursor = collection.find().iterator();
217- try {
218- while(cursor.hasNext()) {
219- flowers.add(cursor.next());
220- }
221- } finally {
222- cursor.close();
223- }
224-
215+ List<Flower> flowers = new ArrayList<>();
216+ collection.find().into(flowers);
225217 System.out.println(flowers);
226218
227219When you run this code, your output should resemble the following:
0 commit comments