Skip to content

Commit 82b8d67

Browse files
committed
NH tech review 2
1 parent 04ea69b commit 82b8d67

File tree

5 files changed

+121
-84
lines changed

5 files changed

+121
-84
lines changed

source/examples/generated/DataClassTest.snippet.filters-query-data-class.kt

Lines changed: 0 additions & 7 deletions
This file was deleted.

source/faq.txt

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,56 +31,37 @@ If you have trouble connecting to a MongoDB deployment, see
3131
the :ref:`Connection Troubleshooting Guide <kotlin-connection-troubleshooting>`
3232
for possible solutions.
3333

34-
How is the Kotlin Driver Different from KMongo?
34+
How is the {+language+} Driver Different from KMongo?
3535
-----------------------------------------------
3636

37-
The Kotlin driver is the official MongoDB driver for Kotlin. It is
38-
developed by the MongoDB team and provides a native API for Kotlin
37+
The {+driver-short+} is the official MongoDB driver for {+language+}. It is
38+
developed by the MongoDB team and provides a native API for {+language+}
3939
applications to connect to MongoDB and work with data. It is implemented
4040
by wrapping the :driver:`MongoDB Java driver </java-drivers/>`.
4141

4242
.. include:: /includes/kmongo-description.rst
4343

44-
The Kotlin driver was developed in collaboration with the creator of KMongo,
44+
The {+driver-short+} was developed in collaboration with the creator of KMongo,
4545
Julien Buret, to give users an officially-supported driver.
4646

47-
The official Kotlin driver and KMongo have generally similar APIs.
48-
Notable similarities between the Kotlin driver and KMongo include:
47+
The official {+driver-short+} and KMongo have generally similar APIs.
48+
Notable similarities between the {+driver-short+} and KMongo include:
4949

5050
- Support for synchronous and coroutine-based operations
5151
- Support using data classes to represent MongoDB documents
52-
- Support KotlinX serialization
53-
- Support for MongoDB CRUD APIs and aggregation
52+
- Support for KotlinX serialization
53+
- Support for MongoDB CRUD API and aggregation API
5454

55-
Although the official Kotlin driver and KMongo are similar, there are some
55+
Although the official {+driver-short+} and KMongo are similar, there are some
5656
key differences:
5757

5858
- The official driver does *not* have built-in support for `reactor <https://projectreactor.io/>`__,
5959
`rxjava2 <https://github.com/ReactiveX/RxJava>`__, `Jackson <https://github.com/FasterXML/jackson>`__,
6060
or `GSON <https://github.com/google/gson>`__.
6161
- The official driver does *not* support MongoDB shell commands.
62-
- The official driver supports type-safe queries with the Builders API,
63-
whereas KMongo uses infix functions and property references for
64-
type-safe queries.
6562

6663
For more detailed information, see :ref:`Migrate from KMongo <kotlin-migrate-kmongo>`.
6764

68-
What is the Difference Between the Kotlin Driver and the Kotlin SDK?
69-
--------------------------------------------------------------------
70-
71-
MongoDB supports both mobile and server-side development in Kotlin. If
72-
you are developing a mobile application for Android or Kotlin
73-
Multiplatform (KMP), you can use the :realm:`MongoDB
74-
Atlas Device Kotlin SDK </sdk/kotlin/>` to access Atlas App Services and
75-
to manage your Realm data.
76-
77-
The {+driver-short+} supports server-side development by providing a
78-
complete library for building idiomatic Kotlin applications. You can
79-
learn how to develop asynchronous applications in this documentation for
80-
the Kotlin Coroutine Driver, or you can view the :driver:`Kotlin Sync
81-
Driver documentation </kotlin-sync/>` to learn more about synchronous
82-
programming.
83-
8465
.. _kotlin-faq-connection-pool:
8566

8667
How Does Connection Pooling Work in the Kotlin Driver?

source/fundamentals/builders/builders-data-classes.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ methods to perform queries on the ``Student`` data class:
129129
.. literalinclude:: /examples/generated/BuildersDataClassTest.snippet.filters-data-class.kt
130130
:language: kotlin
131131

132+
The preceding example includes a query written in **infix notation**, To
133+
learn more about this notation, see `Infix notation
134+
<{+kotlin-docs+}/docs/functions.html#infix-notation>`__ in the
135+
{+language+} reference documentation.
136+
132137
.. _kotlin-data-class-indexes:
133138

134139
Indexes

source/index.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,11 @@ Download the driver by using `Maven <https://maven.apache.org/>`__ or `Gradle
2929
<https://gradle.org/>`__, or set up a runnable project by following our
3030
Quick Start guide.
3131

32-
.. tip:: Other Kotlin Platforms for MongoDB
32+
.. tip:: {+language+} Sync Driver
3333

3434
If your Kotlin application requires synchronous processing, use the
3535
:driver:`Sync Driver </kotlin-sync/>`, which uses synchronous operations
3636
to make blocking calls to MongoDB.
37-
38-
If you are developing an Android or Kotlin Multiplatform (KMP)
39-
application, you can use the :realm:`MongoDB Atlas Device Kotlin SDK </sdk/kotlin/>`
40-
to access Atlas App Services and to manage your Realm data.
4137

4238
Quick Start
4339
-----------

source/migrate-kmongo.txt

Lines changed: 106 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44
Migrate from KMongo
55
===================
66

7+
.. facet::
8+
:name: genre
9+
:values: tutorial
10+
11+
.. meta::
12+
:description: Learn how to migrate your application from KMongo to the official MongoDB Kotlin driver.
13+
:keywords: code example, adapt, syntax
14+
715
.. contents:: On this page
816
:local:
917
:backlinks: none
@@ -45,7 +53,7 @@ Both drivers let you connect to and communicate with MongoDB clusters from a
4553

4654
import com.mongodb.kotlin.client.coroutine.MongoClient
4755

48-
data class Jedi(val name: String, val age: Int)
56+
data class Jedi(val name: String, val age: Int)
4957

5058
// Replace the placeholder with your MongoDB deployment's connection string
5159
val uri = CONNECTION_STRING_URI_PLACEHOLDER
@@ -87,6 +95,15 @@ CRUD and Aggregation
8795
Both drivers provide support for all MongoDB CRUD APIs and aggregation
8896
operations.
8997

98+
.. tip::
99+
100+
If you are accustomed to constructing query filters by using the
101+
infix notation available in KMongo, you can also use this notation to
102+
create filters in the official {+driver-short+} by using extension
103+
methods from the ``mongodb-driver-kotlin-extensions`` package. Select
104+
the :guilabel:`Kotlin Driver Extensions` tab to view an example that
105+
uses this query syntax in the {+driver-short+}.
106+
90107
.. tabs::
91108

92109
.. tab::
@@ -96,42 +113,71 @@ operations.
96113

97114
.. code-block:: kotlin
98115

99-
// Insert a document
100-
val jedi = Jedi("Luke Skywalker", 19)
101-
collection.insertOne(jedi)
116+
// Insert a document
117+
val jedi = Jedi("Luke Skywalker", 19)
118+
collection.insertOne(jedi)
102119

103-
// Find a document
104-
val luke = collection.find(Jedi::name.name, "Luke Skywalker")
105-
val jedis = collection.find(lt(Jedi::age.name, 30)).toList()
120+
// Find a document
121+
val luke = collection.find(Jedi::name.name, "Luke Skywalker")
122+
val jedis = collection.find(lt(Jedi::age.name, 30)).toList()
106123

107-
// Update a document
108-
val filter = Filters.eq(Jedi::name.name, "Luke Skywalker")
109-
val update = Updates.set(Jedi::age.name, 20)
110-
collection.updateOne(filter, update)
124+
// Update a document
125+
val filter = Filters.eq(Jedi::name.name, "Luke Skywalker")
126+
val update = Updates.set(Jedi::age.name, 20)
127+
collection.updateOne(filter, update)
111128

112-
// Delete a document
113-
val filter = Filters.eq(Jedi::name.name, "Luke Skywalker")
114-
collection.deleteOne(filter)
129+
// Delete a document
130+
val filter = Filters.eq(Jedi::name.name, "Luke Skywalker")
131+
collection.deleteOne(filter)
115132

116-
Aggregation pipelines can be built using the ``aggregate`` method and the
117-
``pipeline`` function:
133+
You can build aggregation pipelines by using the ``aggregate()``
134+
method and the ``pipeline`` function:
118135

119136
.. code-block:: kotlin
120137

121-
data class Results(val avgAge: Double)
138+
data class Results(val avgAge: Double)
122139

123-
val resultsFlow = collection.aggregate<Results>(
124-
listOf(
125-
Aggregates.match(Filters.ne(Jedi::name.name, "Luke Skywalker")),
126-
Aggregates.group("\$${Jedi::name.name}",
127-
Accumulators.avg("avgAge", "\$${Jedi::age.name}"))
128-
)
129-
)
130-
resultsFlow.collect { println(it) }
140+
val resultsFlow = collection.aggregate<Results>(
141+
listOf(
142+
Aggregates.match(Filters.ne(Jedi::name.name, "Luke Skywalker")),
143+
Aggregates.group("\$${Jedi::name.name}",
144+
Accumulators.avg("avgAge", "\$${Jedi::age.name}"))
145+
)
146+
)
147+
resultsFlow.collect { println(it) }
131148

132149
See the :ref:`CRUD Operations <kotlin-crud-operations>` and
133150
:ref:`Aggregation <kotlin-aggregation>` documentation for more information.
134-
151+
152+
.. tab::
153+
:tabid: Kotlin Driver Extensions
154+
155+
You can use the Builders API from the
156+
``mongodb-driver-kotlin-extensions`` library to create query
157+
filters and aggregation pipeline stages directly using data class
158+
properties. This library also allows you to create queries by
159+
using infix notation:
160+
161+
.. code-block:: kotlin
162+
163+
data class Jedi(val name: String, val age: Int)
164+
165+
// Find documents
166+
val luke = collection.find(Jedi::name eq "Luke Skywalker")
167+
val jedis = collection.find(Jedi::age lt 30)).toList()
168+
169+
// Update a document
170+
val filter = Jedi::name eq "Luke Skywalker"
171+
val update = Jedi::age.name set 20
172+
collection.updateOne(filter, update)
173+
174+
// Delete a document
175+
val filter = Jedi::name eq "Luke Skywalker"
176+
collection.deleteOne(filter)
177+
178+
To learn more and view examples that use all of the builder
179+
classes, see the :ref:`kotlin-builders-data-classes` guide.
180+
135181
.. tab::
136182
:tabid: KMongo
137183

@@ -169,19 +215,19 @@ operations.
169215
`Extensions Overview <https://litote.org/kmongo/extensions-overview/>`__ KMongo
170216
documentation.
171217

218+
Construct Queries
219+
-----------------
220+
221+
Both drivers provide support for type-safe queries using property references.
222+
172223
.. tip::
173224

174225
If you are accustomed to constructing query filters by using the
175226
infix notation available in KMongo, you can also use this notation to
176227
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-
181-
Construct Queries
182-
-----------------
183-
184-
Both drivers provide support for type-safe queries using property references.
228+
methods from the ``mongodb-driver-kotlin-extensions`` package. Select
229+
the :guilabel:`Kotlin Driver Extensions` tab to view an example that
230+
uses this query syntax in the {+driver-short+}.
185231

186232
.. tabs::
187233

@@ -220,7 +266,32 @@ Both drivers provide support for type-safe queries using property references.
220266
- :ref:`Builders <kotlin-builders-landing>`
221267
- :ref:`Documents <kotlin-document-format>` guide
222268
- `JsonObject <{+api+}/apidocs/bson/org/bson/json/JsonObject.html>`__ API Documentation
223-
269+
270+
.. tab::
271+
:tabid: Kotlin Driver Extensions
272+
273+
You can use the Builders API from the
274+
``mongodb-driver-kotlin-extensions`` library to construct queries
275+
directly on data class properties. This library also allows you to
276+
create queries by using infix notation:
277+
278+
.. code-block:: kotlin
279+
280+
data class Person(val name: String, val gender: String, val age: Int)
281+
data class Result(val name: String)
282+
283+
val collection = database.getCollection<Person>("people")
284+
285+
// Infix Notation Query
286+
val filter = (Person::gender eq "female") and (Person::age gt 29))
287+
val projection = fields(excludeId(), include(Person::name))
288+
289+
val results = collection.find<Result>(filter).projection(projection)
290+
291+
292+
To learn more and view examples that use all of the builder
293+
classes, see the :ref:`kotlin-builders-data-classes` guide.
294+
224295
.. tab::
225296
:tabid: KMongo
226297

@@ -260,15 +331,6 @@ Both drivers provide support for type-safe queries using property references.
260331
- `Typed Queries <https://litote.org/kmongo/typed-queries/>`_
261332
- `Mongo Shell Queries <https://litote.org/kmongo/mongo-shell-support/>`__
262333

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-
272334
Data Typing
273335
-----------
274336

0 commit comments

Comments
 (0)