Skip to content

Commit afb2586

Browse files
authored
DOCSP-36113: add serialization pkgs to quickstart (#150)
* DOCSP-36113: add serialization pkgs to quickstart * vale and comment * small fixes * update rest of QS * vale * JS PR fixes 1
1 parent cf7b97b commit afb2586

File tree

4 files changed

+156
-82
lines changed

4 files changed

+156
-82
lines changed

source/fundamentals.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _kotlin-fundamentals-landing:
2+
13
============
24
Fundamentals
35
============
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. code-block:: kotlin
2+
:caption: build.gradle.kts
3+
:copyable: true
4+
5+
implementation("org.mongodb:bson-kotlinx:{+full-version+}")
6+
// OR
7+
implementation("org.mongodb:bson-kotlin:{+full-version+}")
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. code-block:: xml
2+
:caption: pom.xml
3+
:copyable: true
4+
5+
<dependency>
6+
<groupId>org.mongodb</groupId>
7+
<artifactId>bson-kotlinx</artifactId>
8+
<version>{+full-version+}</version>
9+
</dependency>
10+
<!--OR-->
11+
<dependency>
12+
<groupId>org.mongodb</groupId>
13+
<artifactId>bson-kotlin</artifactId>
14+
<version>{+full-version+}</version>
15+
</dependency>
16+

source/quick-start.txt

Lines changed: 130 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
Quick Start
55
===========
66

7+
.. facet::
8+
:name: genre
9+
:values: tutorial
10+
11+
.. meta::
12+
:keywords: code example, get started, runnable app
13+
714
.. contents:: On this page
815
:local:
916
:backlinks: none
@@ -13,112 +20,146 @@ Quick Start
1320
Introduction
1421
------------
1522

16-
This guide shows you how to create an application that uses the **Kotlin driver**
17-
to connect to a **MongoDB Atlas cluster**. If you prefer to connect to MongoDB
18-
using a different driver or programming language, see our
23+
This guide shows you how to create an application that uses the **{+driver-short+}**
24+
to connect to a **MongoDB Atlas cluster**. If you prefer to connect to
25+
MongoDB by using a different driver or programming language, see the
1926
:driver:`list of official MongoDB drivers <>`.
2027

21-
The Kotlin driver lets you connect to and communicate with MongoDB clusters
28+
The {+driver-short+} lets you connect to and communicate with MongoDB clusters
2229
from a Kotlin application.
2330

24-
MongoDB Atlas is a fully-managed cloud database service that hosts your data
25-
on MongoDB clusters. In this guide, we show you how to get started with your
26-
own free (no credit card required) cluster.
31+
MongoDB Atlas is a fully managed cloud database service that hosts your data
32+
on MongoDB clusters. In this guide, you can learn how to get started with your
33+
own free cluster.
2734

2835
.. tip::
2936

30-
For an additional example of how to build an application in Kotlin using
31-
MongoDB Atlas and the {+driver-long+}, see the
37+
To view another example that demonstrates how to build an
38+
application in Kotlin that connects to MongoDB Atlas, see the
3239
:website:`Getting Started with the {+driver-long+}
33-
</developer/products/mongodb/getting-started-kotlin-driver/>` developer tutorial.
34-
35-
Consult the following steps to connect your Kotlin application with a MongoDB Atlas
36-
cluster.
40+
</developer/products/mongodb/getting-started-kotlin-driver/>`
41+
developer tutorial.
3742

3843
Set up Your Project
3944
-------------------
4045

4146
Install Kotlin
4247
~~~~~~~~~~~~~~
4348

44-
Make sure that your system has Kotlin installed running on JDK 1.8 or later.
49+
Make sure that your system has Kotlin installed and running on JDK 1.8 or later.
4550
For more information on getting started with Kotlin/JVM development,
4651
refer to `Get started with Kotlin/JVM <{+kotlin-docs+}/jvm-get-started.html>`__
4752
in the Kotlin language documentation.
4853

4954
Create the Project
5055
~~~~~~~~~~~~~~~~~~~
5156

52-
This guide shows you how to add the MongoDB Kotlin driver dependencies using
53-
Gradle or Maven. We recommend that you use an integrated development
54-
environment (IDE) such as Intellij IDEA or Eclipse IDE to make it more convenient
55-
to configure Gradle or Maven to build and run your project.
57+
This guide shows you how to add the MongoDB Kotlin driver dependencies
58+
by using Gradle or Maven. We recommend that you use an integrated development
59+
environment (IDE) such as IntelliJ IDEA or Eclipse IDE to configure
60+
Gradle or Maven to build and run your project.
5661

57-
If you are not using an IDE, see
58-
`Creating New Gradle Builds <https://guides.gradle.org/creating-new-gradle-builds/>`_
59-
or `Building Maven <https://maven.apache.org/guides/development/guide-building-maven.html>`_
62+
If you are not using an IDE, see the
63+
`Creating New Gradle Builds
64+
<https://guides.gradle.org/creating-new-gradle-builds/>`__ guide
65+
or the `Building Maven
66+
<https://maven.apache.org/guides/development/guide-building-maven.html>`__ guide
6067
for more information on how to set up your project.
6168

6269
.. _add-mongodb-dependency:
6370

6471
Add MongoDB as a Dependency
6572
~~~~~~~~~~~~~~~~~~~~~~~~~~~
6673

67-
If you are using `Gradle <https://gradle.org/>`__, add the following to your
68-
``build.gradle.kts`` dependencies list:
74+
If you are using `Gradle <https://gradle.org/>`__ to manage your
75+
packages, add the following entry to your ``build.gradle.kts``
76+
dependencies list:
6977

7078
.. include:: /includes/kotlin-driver-coroutine-gradle-versioned.rst
7179

72-
If you are using `Maven <https://maven.apache.org/>`__, add the following to
73-
your ``pom.xml`` dependencies list:
80+
If you are using `Maven <https://maven.apache.org/>`__ to manage your
81+
packages, add the following entry to your ``pom.xml`` dependencies list:
7482

7583
.. include:: /includes/kotlin-driver-coroutine-maven-versioned.rst
7684

77-
Once you configure your dependencies, ensure they are available to your
78-
project which may require running your dependency manager and refreshing
79-
the project in your IDE.
85+
After you configure your dependencies, ensure that they are available to your
86+
project by running the dependency manager and refreshing the
87+
project in your IDE.
88+
89+
Add Serialization Library Dependencies
90+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
To enable the driver to convert between Kotlin objects and BSON, the
93+
data format for documents in MongoDB, you must also add one or both of the
94+
following serialization packages to your application:
95+
96+
- ``bson-kotlinx`` *(Recommended)*
97+
- ``bson-kotlin``
98+
99+
If you are using Gradle to manage your packages, add one of the following
100+
entries to your ``build.gradle.kts`` dependencies list:
101+
102+
.. include:: /includes/serialization-libs-gradle-versioned.rst
103+
104+
If you are using Maven to manage your packages, add one of the following
105+
entries to your ``pom.xml`` dependencies list:
106+
107+
.. include:: /includes/serialization-libs-maven-versioned.rst
108+
109+
After you configure your dependencies, ensure that they are available to your
110+
project by running the dependency manager and refreshing the
111+
project in your IDE.
112+
113+
To learn more about these packages, see
114+
:ref:`fundamentals-kotlin-serialization`.
80115

81116
Create a MongoDB Cluster
82117
------------------------
83118

84119
After setting up your Kotlin project dependencies, create a MongoDB cluster
85-
where you can store and manage your data. Complete the
86-
:atlas:`Get Started with Atlas </getting-started?jmp=docs_driver_kotlin>` guide
120+
in which you can store and manage your data. Complete the
121+
:atlas:`Get Started with Atlas </getting-started?jmp=docs_driver_kotlin>` tutorial
87122
to set up a new Atlas account, create and launch a free tier MongoDB cluster,
88-
load datasets, and interact with the data.
123+
and load sample datasets.
89124

90-
After completing the steps in the Atlas guide, you should have a new MongoDB
91-
cluster deployed in Atlas, a new database user, and sample datasets loaded
92-
into your cluster.
125+
After you complete the steps in the Get Started with Atlas tutorial, you
126+
have a new MongoDB cluster deployed in Atlas, a new database user, and
127+
sample data loaded into your cluster.
93128

94129
Connect to your Cluster
95130
-----------------------
96131

97-
In this step, we create and run an application that uses the MongoDB Kotlin
98-
driver to connect to your MongoDB cluster and run a query on the sample data.
132+
This step shows how to create and run an application that uses the
133+
{+driver-short+} to connect to your MongoDB cluster and run a query on
134+
the sample data.
99135

100-
We pass instructions to the driver on how to connect to your
101-
MongoDB cluster in a string called the *connection string*. This string
102-
includes information on the hostname or IP address and port of your
103-
cluster, authentication mechanism, user credentials when applicable, and
104-
other connection options.
136+
First, you must specify how the driver connects to your MongoDB cluster
137+
by including a *connection string* in your code. This string includes
138+
information on the hostname or IP address and port of your cluster,
139+
authentication mechanism, user credentials, and other connection
140+
options.
105141

106-
If you are connecting to an instance or cluster that is not hosted by Atlas,
107-
see :ref:`Other Ways to Connect to MongoDB <kotlin-other-ways-to-connect>` for
142+
If you are connecting to an instance or cluster that is not hosted on Atlas,
143+
see the :ref:`Other Ways to Connect to MongoDB
144+
<kotlin-other-ways-to-connect>` section of the Connection Guide for
108145
instructions on how to format your connection string.
109146

110147
To retrieve your connection string for the cluster and user you created in
111148
the previous step, log into your Atlas account and navigate to the
112-
:guilabel:`Database` section and click the :guilabel:`Connect` button for the cluster that you
113-
want to connect to as shown below.
149+
:guilabel:`Database` page under Deployment and click the
150+
:guilabel:`Connect` button for your cluster, which is shown in the following
151+
image:
114152

115153
.. figure:: /includes/figures/atlas_connection_select_cluster.png
116154
:alt: Atlas Connection GUI cluster selection screen
117155

118-
Proceed to the :guilabel:`Connect Your Application` step and select the Kotlin driver.
119-
Select "4.10 or later" for the version.
120-
Click the :guilabel:`Copy` icon to copy the *connection string* to your clipboard as
121-
shown below.
156+
Select the :guilabel:`Drivers` option for connection and select
157+
:guilabel:`Kotlin` from the list of drivers and :guilabel:`4.10 or
158+
later` from the version dropdown.
159+
160+
Next, click the :guilabel:`Copy` icon, which is highlighted in the
161+
following image, to copy your *connection string* to
162+
your clipboard:
122163

123164
.. figure:: /includes/figures/atlas_connection_copy_string_kotlin.png
124165
:alt: Atlas Connection GUI connection string screen
@@ -129,20 +170,25 @@ for the next step.
129170
Query Your MongoDB Cluster from Your Application
130171
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
131172

132-
Next, create a file ``QuickStartDataClassExample.kt``. Use the following sample
133-
code to run a query on your sample dataset in MongoDB Atlas, replacing the
134-
value of the ``uri`` variable with your MongoDB Atlas connection string.
135-
The example uses a Kotlin data class to model MongoDB data.
173+
Next, create a file called ``QuickStartDataClassExample.kt`` in your
174+
project.
136175

137-
Ensure you replace the "<password>" section of the connection string with
138-
the password you created for your user that has **atlasAdmin** permissions.
176+
Copy the following sample code into the file and replace the value of
177+
the ``uri`` variable with your MongoDB Atlas connection string that you
178+
saved in the preceding step. Replace the ``"<password>"`` placeholder of
179+
your connection string with the password you set for your user that has
180+
**atlasAdmin** permissions:
139181

140182
.. literalinclude:: /examples/generated/QuickStartDataClassExample.snippet.quick-start-data-class.kt
141183
:language: kotlin
142184
:caption: QuickStartDataClassExample.kt
143185

144-
When you run the ``main`` function, it should output the details
145-
of the movie from the sample dataset which should look something like this:
186+
.. note::
187+
188+
This example uses a Kotlin data class to model MongoDB data.
189+
190+
When you run the ``main`` function, the application prints the details
191+
of a movie document that matches the query, as shown in the following output:
146192

147193
.. code-block:: none
148194
:copyable: false
@@ -153,26 +199,28 @@ of the movie from the sample dataset which should look something like this:
153199
cast=[Michael J. Fox, Christopher Lloyd, Lea Thompson, Crispin Glover]
154200
)
155201

156-
To learn more about using data classes to store and retrieve data, refer to
157-
:ref:`Document Data Format: Data Classes <fundamentals-data-classes>`.
202+
.. tip:: Data Classes
203+
204+
To learn more about using data classes to store and retrieve data,
205+
see the :ref:`fundamentals-data-classes` guide.
158206

159-
If you receive no output or an error, check whether you included the proper
160-
connection string in your Kotlin class, and whether you loaded the sample dataset
161-
into your MongoDB Atlas cluster.
207+
If you don't see any output or receive an error, check whether you
208+
included the proper connection string in your application. Also, confirm
209+
that you successfully loaded the sample dataset into your MongoDB Atlas cluster.
162210

163211
.. important:: Known connection issue when using TLS v1.3
164212

165-
If you encounter an error connecting to your MongoDB instance or cluster
166-
that resembles the following while running your application, you may need
167-
to update your JDK to the latest patch release:
213+
If you encounter the following error while connecting to your MongoDB
214+
instance, you must update your JDK to the latest patch release:
168215

169216
.. code-block:: none
170217
:copyable: false
171218

172219
javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request
173220

174221
This exception is a known issue when using the TLS 1.3 protocol with
175-
specific versions of JDK, but was fixed for the following releases:
222+
specific versions of JDK, but this issue is fixed for the following
223+
JDK versions:
176224

177225
- JDK 11.0.7
178226
- JDK 13.0.3
@@ -181,29 +229,28 @@ into your MongoDB Atlas cluster.
181229
To resolve this error, update your JDK to one of the preceding patch
182230
versions or a newer one.
183231

184-
After completing this step, you should have a working application that uses
185-
the Kotlin driver to connect to your MongoDB cluster, run a query on the
232+
After completing this step, you have a working application that uses
233+
the {+driver-short+} to connect to your MongoDB cluster, run a query on the
186234
sample data, and print out the result.
187235

188236
Working with the Document Class (Alternative)
189237
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
190238

191-
In the previous section, you ran a query on a sample collection to retrieve
192-
data with a data class. In this section, you can learn to
193-
use a `Document <{+api+}/apidocs/bson/org/bson/Document.html>`__ class
239+
The preceding section demonstrates how to run a query on a sample
240+
collection to retrieve data by using a Kotlin data class. This section
241+
shows how to use the `Document <{+api+}/apidocs/bson/org/bson/Document.html>`__ class
194242
to store and retrieve data from MongoDB.
195243

196-
Next, create a new file to contain your application called ``QuickStartDocumentExample.kt``
197-
in the base package directory of your project. Use the following sample
198-
code to run a query on your sample dataset in MongoDB Atlas, replacing the
199-
value of the ``uri`` variable with your MongoDB Atlas connection string.
244+
In a new file called ``QuickStartDocumentExample.kt``, paste the following sample
245+
code to run a query on your sample dataset in MongoDB Atlas. Replace the
246+
value of the ``uri`` variable with your MongoDB Atlas connection string:
200247

201248
.. literalinclude:: /examples/generated/QuickStartDocumentExample.snippet.quick-start-document.kt
202249
:caption: QuickStartDocumentExample.kt
203250
:language: kotlin
204251

205-
When you run the ``main`` function, it should output the details
206-
of the movie from the sample dataset which will look something like this:
252+
When you run the ``main`` function, the application prints the details
253+
of a movie document that matches the query, as shown in the following output:
207254

208255
.. code-block:: json
209256
:copyable: false
@@ -217,12 +264,13 @@ of the movie from the sample dataset which will look something like this:
217264
...
218265
}
219266

220-
If you receive no output or an error, check whether you included the proper
221-
connection string in your Kotlin class, and whether you loaded the sample dataset
222-
into your MongoDB Atlas cluster.
267+
If you don't see any output or receive an error, check whether you
268+
included the proper connection string in your application. Also, confirm
269+
that you successfully loaded the sample dataset into your MongoDB Atlas cluster.
223270

224271
Next Steps
225272
----------
226273

227-
Learn how to read and modify data using the Kotlin driver in the :ref:`Fundamentals
228-
CRUD guide <kotlin-crud-operations>`.
274+
To learn more about the {+driver-short+}, see the
275+
:ref:`kotlin-fundamentals-landing` guides, which describe relevant
276+
concepts in detail and provide code examples for performing different tasks.

0 commit comments

Comments
 (0)