Skip to content

Commit f77d104

Browse files
committed
merge
2 parents 2fe9ea3 + 8e97db7 commit f77d104

File tree

16 files changed

+531
-38
lines changed

16 files changed

+531
-38
lines changed

.github/workflows/check-autobuilder.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Copy Files to docs-shared
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
paths:
8+
- "source/includes/mongodb-compatibility-table-csharp.rst"
9+
- "source/includes/language-compatibility-table-csharp.rst"
10+
workflow_dispatch:
11+
12+
jobs:
13+
copy-file:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v2
18+
19+
- name: Copy mongodb-compat table
20+
uses: dmnemec/copy_file_to_another_repo_action@main
21+
env:
22+
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
23+
with:
24+
source_file: "source/includes/mongodb-compatibility-table-csharp.rst"
25+
destination_repo: "10gen/docs-shared"
26+
destination_folder: "dbx"
27+
user_email: "[email protected]"
28+
user_name: "docs-builder-bot"
29+
commit_message: "Auto-import from docs-csharp"
30+
31+
- name: Copy language-compat table
32+
uses: dmnemec/copy_file_to_another_repo_action@main
33+
env:
34+
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
35+
with:
36+
source_file: "source/includes/language-compatibility-table-csharp.rst"
37+
destination_repo: "10gen/docs-shared"
38+
destination_folder: "dbx"
39+
user_email: "[email protected]"
40+
user_name: "docs-builder-bot"
41+
commit_message: "Auto-import from docs-csharp"

config/redirects

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
define: prefix docs/languages/kotlin/kotlin-sync-driver
22
define: base https://www.mongodb.com/docs/
3-
define: versions master
3+
define: versions v5.1 v5.2 master
4+
5+
symlink: current -> master
46

57
# raw: <source file> -> ${base}/<destination>
68

9+
raw: ${prefix}/ -> ${base}/current/
10+
raw: ${prefix}/master -> ${base}/upcoming/

snooty.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ java-api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}"
3434
core-api = "{+java-api+}/apidocs/mongodb-driver-core"
3535
kotlin-docs = "https://kotlinlang.org"
3636
serialization-version = "1.5.1"
37+
kotlinx-dt-version = "0.6.1"
38+
mongocrypt-version = "{+full-version+}"

source/data-formats/serialization.txt

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,98 @@ deserializes them accordingly.
297297

298298
Retrieving as Document type
299299
Document{{_id=..., _t=Teacher, name=Vivian Lee, department=History}}
300-
Document{{_id=..., _t=Student, name=Kate Parker, grade=10}}
300+
Document{{_id=..., _t=Student, name=Kate Parker, grade=10}}
301+
302+
.. _kotlin-sync-datetime-serialization:
303+
304+
Serialize Dates and Times
305+
-------------------------
306+
307+
In this section, you can learn about using {+language+} serialization to
308+
work with date and time types.
309+
310+
kotlinx-datetime Library
311+
~~~~~~~~~~~~~~~~~~~~~~~~
312+
313+
``kotlinx-datetime`` is a {+language+} library that offers
314+
a high level of control over how your date and time values
315+
are serialized. To use the library, add the ``kotlinx-datetime``
316+
dependency to your project's dependency list.
317+
318+
Select from the following tabs to see how to add the ``kotlinx-datetime``
319+
dependency to your project by using the :guilabel:`Gradle` and
320+
:guilabel:`Maven` package managers:
321+
322+
.. tabs::
323+
324+
.. tab::
325+
:tabid: Gradle
326+
327+
.. code-block:: kotlin
328+
:caption: build.gradle.kts
329+
330+
implementation("org.jetbrains.kotlinx:kotlinx-datetime:{+kotlinx-dt-version+}")
331+
332+
.. tab::
333+
:tabid: Maven
334+
335+
.. code-block:: kotlin
336+
:caption: pom.xml
337+
338+
<dependency>
339+
<groupId>org.jetbrains.kotlinx</groupId>
340+
<artifactId>kotlinx-datetime-jvm</artifactId>
341+
<version>{+kotlinx-dt-version+}</version>
342+
</dependency>
343+
344+
To learn more about this library, see the :github:`kotlinx-datetime repository
345+
</Kotlin/kotlinx-datetime>` on GitHub.
346+
347+
Example Data Class with Dates and Times
348+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349+
350+
After you add the library dependency, you can implement serializers from
351+
the ``kotlinx-datetime`` library that map your data class field values
352+
to the expected types in BSON.
353+
354+
In this example, the driver serializes the fields of
355+
the ``Appointment`` data class with the following behavior:
356+
357+
- ``name``: The driver serializes the value as a string.
358+
359+
- ``date``: The driver uses the ``kotlinx-datetime`` serializer
360+
because the field has the ``@Contextual`` annotation. ``LocalDate``
361+
values are serialized as BSON dates.
362+
363+
- ``time``: The driver serializes the value as a string because it does
364+
not have the ``@Contextual`` annotation. This is the default
365+
serialization behavior for ``LocalTime`` values.
366+
367+
.. literalinclude:: /includes/data-formats/serialization.kt
368+
:language: kotlin
369+
:start-after: start-datetime-data-class
370+
:end-before: end-datetime-data-class
371+
:dedent:
372+
373+
The following example inserts an instance of the ``Appointment`` data
374+
class into the ``appointments`` collection:
375+
376+
.. literalinclude:: /includes/data-formats/serialization.kt
377+
:language: kotlin
378+
:start-after: start-datetime-insertone
379+
:end-before: end-datetime-insertone
380+
:dedent:
381+
382+
In MongoDB, the ``LocalDate`` value is stored as a BSON date, and the
383+
``time`` field is stored as a string by default serialization:
384+
385+
.. code-block:: json
386+
387+
{
388+
"_id": ...,
389+
"name": "Daria Smith",
390+
"date": {
391+
"$date": "2024-10-15T00:00:00.000Z"
392+
},
393+
"time": "11:30",
394+
}

source/encrypt-fields.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. _kotlin-sync-fle:
2+
3+
.. sharedinclude:: dbx/encrypt-fields.rst
4+
5+
.. replacement:: driver-specific-content
6+
7+
.. important:: Compatible Encryption Library Version
8+
9+
The {+driver-short+} uses the `mongodb-crypt
10+
<https://mvnrepository.com/artifact/org.mongodb/mongodb-crypt>`__
11+
encryption library for in-use encryption. This driver version
12+
is compatible with ``mongodb-crypt`` v{+mongocrypt-version+}.
13+
14+
Select from the following :guilabel:`Maven` and
15+
:guilabel:`Gradle` tabs to see how to add the ``mongodb-crypt``
16+
dependency to your project by using the specified manager:
17+
18+
.. tabs::
19+
20+
.. tab:: Maven
21+
:tabid: maven-dependency
22+
23+
.. include:: /includes/security/crypt-maven-versioned.rst
24+
25+
.. tab:: Gradle
26+
:tabid: gradle-dependency
27+
28+
.. include:: /includes/security/crypt-gradle-versioned.rst

source/includes/data-formats/serialization.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ data class Teacher(
7474
) : Person
7575
// end-poly-classes
7676

77+
// start-datetime-data-class
78+
@Serializable
79+
data class Appointment(
80+
val name: String,
81+
@Contextual val date: LocalDate,
82+
val time: LocalTime,
83+
)
84+
// end-datetime-data-class
7785

7886
fun main() {
7987

@@ -126,5 +134,17 @@ fun main() {
126134
}
127135
// end-poly-operations
128136

137+
// start-datetime-insertone
138+
val collection = database.getCollection<Appointment>("appointments")
139+
140+
val apptDoc = Appointment(
141+
"Daria Smith",
142+
LocalDate(2024, 10, 15),
143+
LocalTime(hour = 11, minute = 30)
144+
)
145+
146+
collection.insertOne(apptDoc)
147+
// end-datetime-insertone
148+
129149
}
130150

source/includes/indexes/indexes.kt

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.mongodb.client.model.Indexes
44
import com.mongodb.client.model.Filters
55
import com.mongodb.client.model.Sorts
66
import com.mongodb.client.model.SearchIndexModel
7+
import com.mongodb.client.model.SearchIndexType
78
import com.mongodb.kotlin.client.MongoClient
89
import org.bson.codecs.pojo.annotations.BsonId
910
import org.bson.types.ObjectId
@@ -74,13 +75,35 @@ fun main() {
7475

7576
// start-create-search-index
7677
val index = Document("mappings", Document("dynamic", true))
77-
collection.createSearchIndex("<index name>", index)
78+
collection.createSearchIndex("mySearchIdx", index)
7879
// end-create-search-index
7980

8081
// start-create-search-indexes
81-
val indexOne = SearchIndexModel("<first index name>", Document("mappings", Document("dynamic", true)))
82-
val indexTwo = SearchIndexModel("<second index name>", Document("mappings", Document("dynamic", true)))
83-
collection.createSearchIndexes(listOf(indexOne, indexTwo))
82+
val searchIdxMdl = SearchIndexModel(
83+
"searchIdx",
84+
Document("analyzer", "lucene.standard").append(
85+
"mappings", Document("dynamic", true)
86+
),
87+
SearchIndexType.search()
88+
)
89+
90+
val vectorSearchIdxMdl = SearchIndexModel(
91+
"vsIdx",
92+
Document(
93+
"fields",
94+
listOf(
95+
Document("type", "vector")
96+
.append("path", "embeddings")
97+
.append("numDimensions", 1536)
98+
.append("similarity", "dotProduct")
99+
)
100+
),
101+
SearchIndexType.vectorSearch()
102+
)
103+
104+
collection.createSearchIndexes(
105+
listOf(searchIdxMdl, vectorSearchIdxMdl)
106+
)
84107
// end-create-search-indexes
85108

86109
// start-list-search-indexes
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. code-block:: groovy
2+
3+
dependencies {
4+
implementation("org.mongodb:mongodb-crypt:{+mongocrypt-version+}")
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.. code-block:: xml
2+
3+
<dependencies>
4+
<dependency>
5+
<groupId>org.mongodb</groupId>
6+
<artifactId>mongodb-crypt</artifactId>
7+
<version>{+mongocrypt-version+}</version>
8+
</dependency>
9+
</dependencies>

0 commit comments

Comments
 (0)