@@ -15,30 +15,31 @@ Overview
15
15
--------
16
16
17
17
This page contains a high-level comparison of most of the ways the official
18
- MongoDB Kotlin and the community-developed KMongo driver differ.
18
+ {+driver-long+} and the community-developed KMongo driver differ.
19
19
You can use this page to identify the changes you need to make to migrate from
20
- the deprecated KMongo driver to the official MongoDB Kotlin driver.
20
+ the deprecated KMongo driver to the official {+ driver-long+} .
21
21
22
22
.. include:: /includes/kmongo-description.rst
23
23
24
- The MongoDB Kotlin driver is the officially supported and maintained MongoDB driver for
25
- Kotlin . It is developed by the MongoDB team.
24
+ The {+ driver-long+} is the officially supported and maintained MongoDB driver for
25
+ {+language+} . It is developed by the MongoDB team.
26
26
27
- Although both drivers :ref:`support synchronous and asynchronous operations <kotlin-sync-async-support>`,
28
- the examples on this page will use asynchronous coroutine-based operations.
27
+ Although both drivers :ref:`support synchronous and asynchronous
28
+ operations <kotlin-sync-async-support>`, the examples on this page will
29
+ use asynchronous coroutine-based operations.
29
30
30
31
Connect to MongoDB Cluster
31
32
--------------------------
32
33
33
34
Both drivers let you connect to and communicate with MongoDB clusters from a
34
- Kotlin application.
35
+ {+language+} application.
35
36
36
37
.. tabs::
37
38
38
39
.. tab::
39
40
:tabid: {+driver-long+}
40
41
41
- To connect to a MongoDB cluster using the MongoDB Kotlin driver:
42
+ To connect to a MongoDB cluster using the {+ driver-long+} :
42
43
43
44
.. code-block:: kotlin
44
45
@@ -77,7 +78,7 @@ Kotlin application.
77
78
// Get a collection of documents of type Jedi
78
79
val col = database.getCollection<Jedi>()
79
80
80
- Unlike the MongoDB Kotlin driver, KMongo allows the collection name to be
81
+ Unlike the {+ driver-long+} , KMongo allows the collection name to be
81
82
inferred from the data class name.
82
83
83
84
CRUD and Aggregation
@@ -91,12 +92,12 @@ operations.
91
92
.. tab::
92
93
:tabid: {+driver-long+}
93
94
94
- The MongoDB Kotlin driver also provides functions for all basic CRUD operations:
95
+ The {+ driver-long+} also provides functions for all basic CRUD operations:
95
96
96
97
.. code-block:: kotlin
97
98
98
99
// Insert a document
99
- val jedi =a Jedi("Luke Skywalker", 19)
100
+ val jedi = Jedi("Luke Skywalker", 19)
100
101
collection.insertOne(jedi)
101
102
102
103
// Find a document
@@ -168,6 +169,15 @@ operations.
168
169
`Extensions Overview <https://litote.org/kmongo/extensions-overview/>`__ KMongo
169
170
documentation.
170
171
172
+ .. tip::
173
+
174
+ If you are accustomed to constructing query filters by using the
175
+ infix notation available in KMongo, you can also use this notation to
176
+ create filters in the official {+driver-short+} by using extension
177
+ methods from the ``mongodb-driver-kotlin-extensions`` package. To
178
+ learn more and view examples, see the
179
+ :ref:`kotlin-builders-data-classes` guide.
180
+
171
181
Construct Queries
172
182
-----------------
173
183
@@ -178,7 +188,7 @@ Both drivers provide support for type-safe queries using property references.
178
188
.. tab::
179
189
:tabid: {+driver-long+}
180
190
181
- The MongoDB Kotlin driver uses the Builders API to construct queries.
191
+ The {+ driver-long+} uses the Builders API to construct queries.
182
192
Alternatively, you can use the ``Document`` class.
183
193
184
194
.. code-block:: kotlin
@@ -198,14 +208,14 @@ Both drivers provide support for type-safe queries using property references.
198
208
val projection = Document().append("_id", 0).append("email", 1)
199
209
val results = collection.find<Results>(filter).projection(projection)
200
210
201
- To map a KMongo string query to the Kotlin driver, you can use the ``JsonObject`` class.
211
+ To map a KMongo string query to the {+ driver-short+} , you can use the ``JsonObject`` class.
202
212
203
213
.. code-block:: kotlin
204
214
205
215
val query = JsonObject("{\"name\": \"Gabriel Garc\\u00eda M\\u00e1rquez\"}")
206
216
val jsonResult = collection.find(query).firstOrNull()
207
217
208
- For more information, see the following Kotlin driver documentation:
218
+ For more information, see the following {+ driver-short+} documentation:
209
219
210
220
- :ref:`Builders <kotlin-builders-landing>`
211
221
- :ref:`Documents <kotlin-document-format>` guide
@@ -250,10 +260,19 @@ Both drivers provide support for type-safe queries using property references.
250
260
- `Typed Queries <https://litote.org/kmongo/typed-queries/>`_
251
261
- `Mongo Shell Queries <https://litote.org/kmongo/mongo-shell-support/>`__
252
262
263
+ .. tip::
264
+
265
+ If you are accustomed to constructing query filters by using the
266
+ infix notation available in KMongo, you can also use this notation to
267
+ create filters in the official {+driver-short+} by using extension
268
+ methods from the ``mongodb-driver-kotlin-extensions`` package. To
269
+ learn more and view examples, see the
270
+ :ref:`kotlin-builders-data-classes` guide.
271
+
253
272
Data Typing
254
273
-----------
255
274
256
- Both drivers support the use of Kotlin data classes as well as the ``Document`` class to
275
+ Both drivers support the use of {+language+} data classes as well as the ``Document`` class to
257
276
model the data stored in a MongoDB collection. The ``Document``
258
277
class lets you model data represented in a MongoDB collection in a flexible format.
259
278
@@ -263,7 +282,7 @@ class lets you model data represented in a MongoDB collection in a flexible form
263
282
:tabid: {+driver-long+}
264
283
265
284
You can use data classes and ``Document`` classes to model data with the
266
- MongoDB Kotlin driver:
285
+ {+ driver-long+} :
267
286
268
287
.. code-block:: kotlin
269
288
@@ -302,17 +321,17 @@ Data Serialization
302
321
------------------
303
322
304
323
Both drivers provide support for serializing and deserializing data objects
305
- in Kotlin to and from BSON.
324
+ in {+language+} to and from BSON.
306
325
307
326
.. tabs::
308
327
309
328
.. tab::
310
329
:tabid: {+driver-long+}
311
330
312
- You can serialize data classes in the Kotlin driver using both automatic
331
+ You can serialize data classes in the {+ driver-short+} using both automatic
313
332
data class codecs as well as the ``kotlinx.serialization`` library. The
314
333
driver provides an efficient ``Bson`` serializer that handles the
315
- serialization of Kotlin objects to BSON data.
334
+ serialization of {+language+} objects to BSON data.
316
335
317
336
.. code-block:: kotlin
318
337
@@ -326,7 +345,7 @@ in Kotlin to and from BSON.
326
345
val manufacturer: String = "Acme" // Use instead of @BsonProperty
327
346
)
328
347
329
- To learn more, see the :ref:`Kotlin Serialization <fundamentals-kotlin-serialization>`
348
+ To learn more, see the :ref:`{+language+} Serialization <fundamentals-kotlin-serialization>`
330
349
documentation.
331
350
332
351
If you use the ``Document`` class to represent your collection, you can
@@ -381,9 +400,9 @@ Both drivers support synchronous and asynchronous operations.
381
400
.. tab::
382
401
:tabid: {+driver-long+}
383
402
384
- The MongoDB Kotlin driver also has separate libraries for synchronous and
385
- asynchronous operations. However, the Kotlin driver only has built-in support
386
- for coroutines as an asynchronous paradigm. The MongoDB Kotlin driver does not
403
+ The {+ driver-long+} also has separate libraries for synchronous and
404
+ asynchronous operations. However, the {+ driver-short+} only has built-in support
405
+ for coroutines as an asynchronous paradigm. The {+ driver-long+} does not
387
406
currently provide support for other asynchronous paradigms such as Reactive
388
407
Streams, Reactor, or RxJava2.
389
408
@@ -514,5 +533,5 @@ What Next?
514
533
----------
515
534
516
535
Now that you have learned about the differences between KMongo and the MongoDB
517
- Kotlin driver, see the :ref:`Quick Start <kotlin-quickstart>` to get
518
- started using the KMongo Kotlin driver.
536
+ {+ driver-short+} , see the :ref:`Quick Start <kotlin-quickstart>` to get
537
+ started using the KMongo {+ driver-short+} .
0 commit comments