Skip to content

Commit 0162a25

Browse files
committed
Address RR feedback
1 parent 5acaf2b commit 0162a25

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

source/builders.txt

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _kotlin-sync-builders:
22

3-
================
4-
Use Builders API
5-
================
3+
===============================
4+
Implement Builders Code Pattern
5+
===============================
66

77
.. contents:: On this page
88
:local:
@@ -22,29 +22,31 @@ Use Builders API
2222
Overview
2323
--------
2424

25-
This page describes how to use the builders API and demonstrates the utility provided by
26-
builder classes.
25+
This page describes how to implement the builders pattern in your code and describes
26+
benefits of using builder classes.
2727

28-
The {+driver-short+} provides type-safe classes and methods that enable developers to
29-
efficiently build queries and aggregations.
28+
The {+driver-short+} provides type-safe builders classes and methods that enable developers to
29+
efficiently build queries and aggregations. To learn more about the builders pattern,
30+
see `Type-safe builders <https://kotlinlang.org/docs/type-safe-builders.html>`__ in the
31+
{+language+} documentation.
3032

31-
Why Use Builders?
32-
-----------------
33+
Why Use the Builders Code Pattern?
34+
----------------------------------
3335

34-
When using the MongoDB shell or plain Kotlin to construct BSON query documents, you are not
36+
If you use only plain {+language+} to construct BSON query documents, you are not
3537
able to identify errors in your code until runtime.
3638

37-
With builder classes, you can write operators as methods and any syntax errors will be
38-
caught at compile time.
39+
When you use builder classes, you can write operators as methods and any syntax errors
40+
will be caught at compile time.
3941

4042
Example
4143
-------
4244

43-
This section describes three methods of fetching the ``email`` field values of documents
45+
This section provides three equivalent ways to fetch the ``email`` field values of documents
4446
in the ``users`` collection that meet the following criteria:
4547

46-
- Users that identify as ``female``
47-
- Users that are older than ``29``
48+
- ``gender`` value is ``"female"``
49+
- ``age`` value is greateer than ``29``
4850

4951
The following data class models the documents in the ``users`` collection:
5052

@@ -64,19 +66,20 @@ The following data class models the results returned by our query:
6466
:copyable:
6567
:dedent:
6668

67-
Using the MongoDB Shell
68-
~~~~~~~~~~~~~~~~~~~~~~~
69+
MongoDB Query API
70+
~~~~~~~~~~~~~~~~~
6971

70-
The following sample executes the previously defined query using the MongoDB shell:
72+
The following sample performs the query by using the MongoDB Query API:
7173

7274
.. code-block:: js
7375

7476
collection.find({ "gender": "female", "age" : { "$gt": 29 }}, { "_id": 0, "email": 1 })
7577

76-
Without Using Builders
77-
~~~~~~~~~~~~~~~~~~~~~~
78+
Document Class Filter
79+
~~~~~~~~~~~~~~~~~~~~~
7880

79-
The following example executes the previously defined query using plain {+language+}:
81+
The following example performs the query by using the ``Document`` class to construct the
82+
query filter:
8083

8184
.. literalinclude:: /includes/builders/builders.kt
8285
:start-after: start-find
@@ -85,10 +88,10 @@ The following example executes the previously defined query using plain {+langua
8588
:copyable:
8689
:dedent:
8790

88-
Using Builders
89-
~~~~~~~~~~~~~~
91+
Builders Pattern
92+
~~~~~~~~~~~~~~~~
9093

91-
The following example executes the previously defined query using the builders API:
94+
The following example performs the query by using the builders pattern:
9295

9396
.. literalinclude:: /includes/builders/builders.kt
9497
:start-after: start-find-builders
@@ -102,6 +105,9 @@ The following example executes the previously defined query using the builders A
102105
.. Available Builders
103106
.. ------------------
104107

108+
.. The following pages describe how to implement the different classes of builders
109+
.. available in the {+driver-short+}.
110+
105111
.. - :ref:`Aggregates <aggregates-builders>` for building aggregation pipelines.
106112
.. - :ref:`Filters <filters-builders>` for building query filters.
107113
.. - :ref:`Indexes <indexes-builders>` for creating index keys.

source/includes/builders/builders.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ import org.bson.types.ObjectId
99

1010
// start-user-class
1111
data class User(
12-
@BsonId
13-
val id: ObjectId,
12+
@BsonId val id: ObjectId,
1413
val gender: String,
1514
val age: Int,
1615
val email: String
1716
)
1817
// end-user-class
1918

2019
// start-result-class
21-
data class Result(
20+
data class Email(
2221
val email: String
2322
)
2423
// end-result-class
@@ -38,7 +37,7 @@ fun main() {
3837
// start-find
3938
val filter = Document("gender", "female").append("age", Document("\$gt", 29))
4039
val projection = Document("_id", 0).append("email", 1)
41-
val results = collection.find<Result>(filter).projection(projection)
40+
val results = collection.find<Email>(filter).projection(projection)
4241
// end-find
4342

4443
// start-find-builders
@@ -52,7 +51,7 @@ fun main() {
5251
Projections.include("email")
5352
)
5453

55-
val results = collection.find<Result>(filter).projection(projection)
54+
val results = collection.find<Email>(filter).projection(projection)
5655
// end-find-builders
5756
}
5857

0 commit comments

Comments
 (0)