@@ -40,14 +40,14 @@ If you are using `Gradle <https://gradle.org/>`__, add the following to your
4040
4141.. include:: /includes/quick-start/gradle-versioned.rst
4242
43- Once you configure your dependencies, make sure they are available to your
44- project which involves running your dependency manager and/or refreshing
43+ Once you configure your dependencies, ensure they are available to your
44+ project which may require running your dependency manager and refreshing
4545the project in your IDE.
4646
4747.. note::
48- You may need to configure the JDK version in your IDE and/or dependency
48+ You may need to configure the JDK version in your IDE and dependency
4949 file. Refer to the documentation provided by maintainers of your IDE
50- and/or dependency management system.
50+ and dependency management system.
5151
5252 For example, if you build with Maven in the IntelliJ IDE, you need to
5353 specify your JDK version explicitly in the ``properties`` section in your
@@ -75,40 +75,59 @@ Next, create a file to contain your application called ``QuickStart.java``
7575in the base package directory of your project. Use the following sample
7676code to run a query on your sample dataset in MongoDB Atlas, replacing the
7777value of the ``uri`` variable with your MongoDB Atlas connection string.
78- Make sure to replace the "<password>" section of the connection string with
78+ Ensure you replace the "<password>" section of the connection string with
7979the password you created for your user that has **atlasAdmin** permissions:
8080
81- .. code-block:: java
81+ .. literalinclude:: /includes/quick-start/code-snippets/QuickStart.java
82+ :start-after: begin QuickStart
83+ :end-before: end QuickStart
84+ :language: java
85+ :dedent:
8286
83- import static com.mongodb.client.model.Filters.eq;
87+ .. include:: /includes/quick-start/query-output.rst
8488
85- import org.bson.Document;
89+ After completing this step, you should have a working application that uses
90+ the Java driver to connect to your MongoDB cluster, run a query on the
91+ sample data, and print out the result.
8692
87- import com.mongodb.client.MongoClient;
88- import com.mongodb.client.MongoClients;
89- import com.mongodb.client.MongoCollection;
90- import com.mongodb.client.MongoDatabase;
93+ Working with POJOs (Optional)
94+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9195
92- public static void main( String[] args ) {
96+ In the previous section, you ran a query on a sample collection to retrieve
97+ data in the map-like class ``Document``. In this section, you can learn to
98+ use your own Plain Old Java Object (POJO) to store and retrieve data from
99+ MongoDB.
93100
94- String uri = "mongodb+srv://<user>:<password>@<cluster-url>?retryWrites=true&w=majority";
95- MongoClient mongoClient = MongoClients.create(uri);
101+ Create a file called ``Movie.java`` in the base package directory of your
102+ project and add the following code for a class that includes the following
103+ fields, setters, and getters:
96104
97- MongoDatabase database = mongoClient.getDatabase("sample_mflix");
98- MongoCollection<Document> collection = database.getCollection("movies");
105+ .. literalinclude:: /includes/quick-start/code-snippets/Movie.java
106+ :start-after: begin moviePojo
107+ :end-before: end moviePojo
108+ :language: java
109+ :dedent:
99110
100- Document doc = collection.find(eq("title", "Back to the Future")).first();
101- System.out.println(doc.toJson());
111+ Create a new file ``QuickStartPojoExample.java`` in the same package
112+ directory as your ``Movie`` file in your project. Use the following sample
113+ code to run a query on your sample dataset in MongoDB Atlas, replacing the
114+ value of the ``uri`` variable with your MongoDB Atlas connection string.
115+ Ensure you replace the "<password>" section of the connection string with
116+ the password you created for your user that has **atlasAdmin** permissions:
102117
103- mongoClient.close();
104- }
118+ .. literalinclude:: /includes/quick-start/code-snippets/QuickStartPojoExample.java
119+ :start-after: begin PojoQuickstart
120+ :end-before: end PojoQuickstart
121+ :language: java
122+ :dedent:
105123
106- .. include:: /includes/quick-start/query-output.rst
124+ .. include:: /includes/quick-start/pojo- query-output.rst
107125
108- After completing this step, you should have a working application that uses
109- the Java driver to connect to your MongoDB cluster, run a query on the
110- sample data, and print out the result.
126+ See the following links for more information on using POJOs to store and
127+ retrieve data:
111128
129+ - :doc:`Guide on using POJOs to store and retrieve data</fundamentals/data-formats/document-data-format-pojo>`
130+ - :doc:`Guide on custom serialization of POJOs </fundamentals/data-formats/pojo-customization>`
112131
113132Next steps
114133----------
0 commit comments