Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/workflows/check-autobuilder.yml

This file was deleted.

1 change: 1 addition & 0 deletions snooty.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ java-api = "https://mongodb.github.io/mongo-java-driver/{+version-number+}"
core-api = "{+java-api+}/apidocs/mongodb-driver-core"
kotlin-docs = "https://kotlinlang.org"
serialization-version = "1.5.1"
kotlinx-dt-version = "0.6.1"
96 changes: 95 additions & 1 deletion source/data-formats/serialization.txt
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,98 @@ deserializes them accordingly.

Retrieving as Document type
Document{{_id=..., _t=Teacher, name=Vivian Lee, department=History}}
Document{{_id=..., _t=Student, name=Kate Parker, grade=10}}
Document{{_id=..., _t=Student, name=Kate Parker, grade=10}}

.. _kotlin-sync-datetime-serialization:

Serialize Dates and Times
-------------------------

In this section, you can learn about using {+language+} serialization to
work with date and time types.

kotlinx-datetime Library
~~~~~~~~~~~~~~~~~~~~~~~~

``kotlinx-datetime`` is a {+language+} library that offers
a high level of control over how your date and time values
are serialized. To use the library, add the ``kotlinx-datetime``
dependency to your project's dependency list.

Select from the following tabs to see how to add the ``kotlinx-datetime``
dependency to your project by using the :guilabel:`Gradle` and
:guilabel:`Maven` package managers:

.. tabs::

.. tab::
:tabid: Gradle

.. code-block:: kotlin
:caption: build.gradle.kts

implementation("org.jetbrains.kotlinx:kotlinx-datetime:{+kotlinx-dt-version+}")

.. tab::
:tabid: Maven

.. code-block:: kotlin
:caption: pom.xml

<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-datetime-jvm</artifactId>
<version>{+kotlinx-dt-version+}</version>
</dependency>

To learn more about this library, see the :github:`kotlinx-datetime repository
</Kotlin/kotlinx-datetime>` on GitHub.

Example Data Class with Dates and Times
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

After you add the library dependency, you can implement serializers from
the ``kotlinx-datetime`` library that map your data class field values
to the expected types in BSON.

In the following example, the driver serializes the fields of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: [nit] Since this sentence repeats "following", you could reword to just "this example":

Suggested change
In the following example, the driver serializes the fields of
In this example, the driver serializes the fields of

the ``Appointment`` data class with the following behavior:

- ``name``: The driver serializes the value as a string.

- ``date``: The driver uses the ``kotlinx-datetime`` serializer
because the field has the ``@Contextual`` annotation. ``LocalDate``
values are serialized as BSON dates.

- ``time``: The driver serializes the value as a string because it does
not have the ``@Contextual`` annotation. This is the default
serialization behavior for ``LocalTime`` values.

.. literalinclude:: /includes/data-formats/serialization.kt
:language: kotlin
:start-after: start-datetime-data-class
:end-before: end-datetime-data-class
:dedent:

The following example inserts an instance of the ``Appointment`` data
class into MongoDB:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: you can be more specific about where you're inserting data

Suggested change
class into MongoDB:
class into a MongoDB collection named "appointments":


.. literalinclude:: /includes/data-formats/serialization.kt
:language: kotlin
:start-after: start-datetime-insertone
:end-before: end-datetime-insertone
:dedent:

In MongoDB, the ``LocalDate`` value is stored as a BSON date, and the
``time`` field is stored as a string by default serialization:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: remove extra space

Suggested change
``time`` field is stored as a string by default serialization:
``time`` field is stored as a string by default serialization:


.. code-block:: json

{
"_id": ...,
"name": "Daria Smith",
"date": {
"$date": "2024-10-15T00:00:00.000Z"
},
"time": "11:30",
}
20 changes: 20 additions & 0 deletions source/includes/data-formats/serialization.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ data class Teacher(
) : Person
// end-poly-classes

// start-datetime-data-class
@Serializable
data class Appointment(
val name: String,
@Contextual val date: LocalDate,
val time: LocalTime,
)
// end-datetime-data-class

fun main() {

Expand Down Expand Up @@ -126,5 +134,17 @@ fun main() {
}
// end-poly-operations

// start-datetime-insertone
val collection = database.getCollection<Appointment>("appointments")

val apptDoc = Appointment(
"Daria Smith",
LocalDate(2024, 10, 15),
LocalTime(hour = 11, minute = 30)
)

collection.insertOne(apptDoc)
// end-datetime-insertone

}

30 changes: 26 additions & 4 deletions source/includes/indexes/indexes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,35 @@ fun main() {

// start-create-search-index
val index = Document("mappings", Document("dynamic", true))
collection.createSearchIndex("<index name>", index)
collection.createSearchIndex("mySearchIdx", index)
// end-create-search-index

// start-create-search-indexes
val indexOne = SearchIndexModel("<first index name>", Document("mappings", Document("dynamic", true)))
val indexTwo = SearchIndexModel("<second index name>", Document("mappings", Document("dynamic", true)))
collection.createSearchIndexes(listOf(indexOne, indexTwo))
val searchIdxMdl = SearchIndexModel(
"searchIdx",
Document("analyzer", "lucene.standard").append(
"mappings", Document("dynamic", true)
),
SearchIndexType.search()
)

val vectorSearchIdxMdl = SearchIndexModel(
"vsIdx",
Document(
"fields",
listOf(
Document("type", "vector")
.append("path", "embeddings")
.append("numDimensions", 1536)
.append("similarity", "dotProduct")
)
),
SearchIndexType.vectorSearch()
)

collection.createSearchIndexes(
listOf(searchIdxMdl, vectorSearchIdxMdl)
)
// end-create-search-indexes

// start-list-search-indexes
Expand Down
37 changes: 22 additions & 15 deletions source/indexes/atlas-search-index.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.. _kotlin-sync-atlas-search-index:
.. _kotlin-sync-search-avs-indexes:

====================
Atlas Search Indexes
====================
======================================
Atlas Search and Vector Search Indexes
======================================

.. contents:: On this page
:local:
Expand All @@ -20,12 +21,23 @@ Atlas Search Indexes
Overview
--------

:atlas:`Atlas Search </atlas-search>` enables you to perform full-text searches on
You can programmatically manage your :atlas:`Atlas Search
</atlas-search>` and :atlas:`Atlas Vector Search
</atlas-vector-search/vector-search-overview/>` indexes by using the
{+driver-short+}.

Atlas Search enables you to perform full-text searches on
collections hosted on MongoDB Atlas. Atlas Search indexes specify the behavior of
the search and which fields to index.

You can call the following methods on a collection to manage your Atlas Search
indexes:
Atlas Vector Search enables you to perform semantic searches on vector
embeddings stored in MongoDB Atlas. Vector Search indexes define the
indexes for the vector embeddings that you want to query and the boolean,
date, objectId, numeric, string, or UUID values that you want to use to
pre-filter your data.

You can call the following methods on a collection to manage your Atlas
Search and Vector Search indexes:

- ``createSearchIndex()``
- ``createSearchIndexes()``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Does the note below (can't comment on it directly) apply just to Atlas Search indexes? If it applies to Vector search index methods as well, I'd update it to reflect that

Expand All @@ -50,13 +62,7 @@ Create a Search Index
You can use the `createSearchIndex()
<{+api+}/com.mongodb.kotlin.client/-mongo-collection/create-search-index.html>`__
and the `createSearchIndexes() <{+api+}/com.mongodb.kotlin.client/-mongo-collection/create-search-indexes.html>`__
methods to create one or more Atlas Search indexes.

You can also use these methods to create Atlas Vector Search Indexes.
Atlas Vector Search enables you to perform semantic searches on vector
embeddings stored in MongoDB Atlas. To learn more about this feature,
see the :atlas:`Atlas Vector Search Overview
</atlas-vector-search/vector-search-overview/>`.
methods to create one or more Atlas Search or Vector Search indexes.

The following code example shows how to create an Atlas Search index:

Expand All @@ -66,7 +72,8 @@ The following code example shows how to create an Atlas Search index:
:end-before: end-create-search-index
:dedent:

The following code example shows how to create multiple indexes:
The following code example shows how to create Search and
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S:

Suggested change
The following code example shows how to create Search and
The following code example shows how to create Atlas Search and

Vector Search indexes in one call:

.. literalinclude:: /includes/indexes/indexes.kt
:language: kotlin
Expand All @@ -76,7 +83,7 @@ The following code example shows how to create multiple indexes:

To learn more about the syntax used to define Atlas Search indexes, see the
:atlas:`Review Atlas Search Index Syntax </atlas-search/index-definitions>` guide
in the Atlas manual.
in the Atlas documentation.

.. _kotlin-sync-atlas-search-index-list:

Expand Down
27 changes: 27 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,39 @@ What's New

Learn what's new in:

* :ref:`Version 5.2 <kotlin-sync-version-5.2>`
* :ref:`Version 5.1.3 <kotlin-sync-version-5.1.3>`
* :ref:`Version 5.1.2 <kotlin-sync-version-5.1.2>`
* :ref:`Version 5.1.1 <kotlin-sync-version-5.1.1>`
* :ref:`Version 5.1 <kotlin-sync-version-5.1>`
* :ref:`Version 5.0 <kotlin-sync-version-5.0>`

.. _kotlin-sync-version-5.2:

What's New in 5.2
-----------------

The 5.2 driver release includes the following new features,
improvements, and fixes:

.. sharedinclude:: dbx/jvm/v5.2-wn-items.rst

.. replacement:: avs-index-link

the :ref:`kotlin-sync-search-avs-indexes` guide

- Adds support for serializers from the ``kotlinx-datetime`` library
that let you map {+language+} date and time types to BSON as the
expected types instead of as strings. To learn more, see the
:ref:`kotlin-sync-datetime-serialization` section of the {+language+}
Serialization guide.

- Supports serialization of `JsonElement
<{+kotlin-docs+}/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-element/>`__
values. To work with the ``JsonElement`` type, you must add the
``kotlinx-serialization-json`` library as a dependency in your
application.

.. _kotlin-sync-version-5.1.3:

What's New in 5.1.3
Expand Down
Loading