-
Notifications
You must be signed in to change notification settings - Fork 20
DOCSP-36218: builders with dataclass properties #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
c86f88c
e2575be
6050c93
508d1ca
20c31c6
b056571
f9fa810
5239a20
c1e534b
d06be1f
0c0f1de
c8a2c9c
9311ba6
050ac55
7825e03
2b5b815
04ea69b
82b8d67
6fef9d5
19278b9
11d4686
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
val record = DataStorage("SSD", 120.0) | ||
// Infixed query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this referenced somewhere? |
||
DataStorage::productName.eq(record.productName) | ||
// Nested query | ||
val bson = eq(DataStorage::productName, record.productName) | ||
// Kmongo DSL | ||
val filter = DataStorage::productName eq record.productName |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,8 @@ type, which you can pass to any method that expects a query filter. | |
|
||
import com.mongodb.client.model.Filters.* | ||
|
||
Most of the ``Filter`` examples in this guide use the following sample collection ``paints``: | ||
Most of the ``Filters`` examples in this guide use the following sample | ||
collection ``paints``: | ||
|
||
.. code-block:: json | ||
|
||
|
@@ -81,6 +82,13 @@ with the Kotlin driver: | |
.. literalinclude:: /examples/generated/FiltersBuildersTest.snippet.paint-order-data-class.kt | ||
:language: kotlin | ||
|
||
.. tip:: Filters and Data Class Properties | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question for technical reviewer: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The This will be a one stop page/section for people familiar with KMongo or who want to use the driver in a more typesafe manner. |
||
|
||
You can use methods from the ``Filters`` class directly with data class | ||
properties. To learn more and view examples, see the | ||
:ref:`kotlin-data-class-query` section of the Document Data Format: | ||
Data Classes guide. | ||
|
||
.. _comparison: | ||
|
||
Comparison | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ Overview | |
-------- | ||
|
||
In this guide, you can learn how to store and retrieve data in the | ||
{+driver-long+} using **Kotlin data classes**. | ||
{+driver-long+} by using **{+language+} data classes**. | ||
|
||
Serialize and Deserialize a Data Class | ||
-------------------------------------- | ||
|
||
The driver natively supports encoding and decoding Kotlin data classes for | ||
The driver natively supports encoding and decoding {+language+} data classes for | ||
MongoDB read and write operations using the **default codec registry**. The | ||
default codec registry is a collection of classes called **codecs** that | ||
define how to encode and decode Kotlin and Java types. | ||
|
@@ -85,6 +85,30 @@ operation adds the ``releaseDate`` field to the document with a | |
For more information about this feature, see :ref:`Specify Return Type | ||
<db-coll-specify-return-type>` in the Databases and Collections guide. | ||
|
||
.. _kotlin-data-class-query: | ||
|
||
Querying Data Classes | ||
--------------------- | ||
|
||
You can use helpers from the ``Filters`` builders class to query on data | ||
class properties. To learn more about this class, see the | ||
:ref:`filters-builders` guide. | ||
|
||
The following code uses the ``Filters.eq()`` method to | ||
construct the same query on the ``DataStorage`` data class in multiple syntaxes: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question for technical reviewer: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in the previous comment, I suggest grouping all these extensions (not just Filters) into a single section. This will improve the discoverability of extensions beyond the common Filter/equality use case. Additionally, we should emphasize that this module is optional (i.e we need to pull |
||
|
||
.. literalinclude:: /examples/generated/DataClassTest.snippet.filters-query-data-class.kt | ||
:language: kotlin | ||
|
||
.. tip:: Filters and Data Class Annotations | ||
|
||
When you use ``Filters`` class helpers to construct queries on data | ||
classes, the methods respect your data class annotations from the | ||
``bson-kotlin`` and ``bson-kotlinx`` packages. To learn more about | ||
annotations, see the :ref:`fundamentals-data-class-annotations` | ||
section of this guide and the :ref:`kotlin-data-class-annotation` | ||
section in the {+language+} Serialization guide. | ||
|
||
.. _fundamentals-data-class-annotations: | ||
|
||
Specify Component Conversion Using Annotations | ||
|
@@ -105,7 +129,7 @@ You can use the following annotations on data classes: | |
- Description | ||
|
||
* - ``BsonId`` | ||
- Marks a property to serialize as the _id property. | ||
- Marks a property to serialize as the ``_id`` property. | ||
|
||
* - ``BsonProperty`` | ||
- Specifies a custom document field name when converting the data class | ||
|
Uh oh!
There was an error while loading. Please reload this page.