Skip to content

Commit 6ae5962

Browse files
DOCSP-15177 definition of builders (#90)
* added a more in depth definition of builders
1 parent f0bf0ec commit 6ae5962

File tree

6 files changed

+58
-24
lines changed

6 files changed

+58
-24
lines changed

source/fundamentals/builders.txt

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,66 @@ Builders
1919
:depth: 2
2020
:class: singlecol
2121

22-
This section includes guides on how to use each of the available builders, and demonstrates the utility the Java driver
23-
builder classes provide.
22+
This section includes guides on how to use each of the available
23+
builders, and demonstrates the utility the Java driver builder classes
24+
provide.
2425

2526
Overview
2627
--------
2728

28-
The Java driver provides classes to make it easier to use CRUD operations and the Aggregation API. The static utility methods
29-
allow you to build a query more succinctly.
29+
The Java driver provides classes to simplify the process for developers
30+
to use CRUD operations and the Aggregation API. The static utility methods allow you
31+
to build a query more efficiently.
3032

33+
Why Use Builders?
34+
-----------------
3135

32-
Imagine we want to send a marketing email to all users in our users collection that identify as "female" gender and are older than "29".
33-
We only need their email address, so we'll ensure our query doesn't return data we pay bandwidth
34-
costs for but don't need.
36+
Using the builders class, you leverage the power of:
3537

36-
Using JSON and the MongoDB shell, the query would look something like:
38+
- The Java compiler and the IDE to find errors during development
39+
- The IDE for discovery and code completion
40+
41+
The Java compiler and the IDE catch errors such as misspelled
42+
operators early on. When using the MongoDB shell or plain Java, you
43+
write operators as strings and get no visual indication of a problem,
44+
pushing these errors to runtime instead of compile time
45+
46+
With the builder classes, you write operators as methods. The IDE
47+
instantly underlines and gives you a red bar on the right indicating
48+
something is wrong. While developing, the IDE also shows you with the
49+
methods you can use. It automatically completes your code with
50+
placeholder parameters once you select which method you want to use.
51+
52+
Scenario
53+
--------
54+
55+
Imagine we want to send a marketing email to all users in our ``users``
56+
collection with the following criteria:
57+
58+
- Users that identify as "female" gender
59+
- Users that are older than "29"
60+
61+
We only want their email address, so we'll ensure our query doesn't
62+
return data we pay bandwidth costs for but don't need.
63+
64+
Using the MongoDB Shell
65+
~~~~~~~~~~~~~~~~~~~~~~~
3766

3867
.. code-block:: js
3968

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

42-
Without builders, we construct the query in Java as:
71+
Without Using Builders
72+
~~~~~~~~~~~~~~~~~~~~~~
4373

4474
.. code-block:: java
4575

46-
Bson filter = new Document().append("gender", "female").append("age", new Document().append("$gt", 28));
76+
Bson filter = new Document().append("gender", "female").append("age", new Document().append("$gt", 29));
4777
Bson projection = new Document().append("_id", 0).append("email", 1);
4878
collection.find(filter).projection(projection);
4979

50-
With builders, the query becomes:
80+
Using Builders
81+
~~~~~~~~~~~~~~
5182

5283
.. code-block:: java
5384

source/fundamentals/builders/filters.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ Filters Builders
1414

1515
Overview
1616
--------
17+
1718
In this guide, we show you how to use **builders** to specify
1819
**filters** for your queries.
1920

20-
Builders are classes provided by the MongoDB Java driver that allow you
21-
to use the builder pattern to interact with your MongoDB instance. The
22-
builders provided by the MongoDB Java driver can improve the readability
23-
of your code. See the :doc:`Builders </fundamentals/builders/>` page
24-
for a list of Builders available in the Java driver.
21+
Builders are classes provided by the MongoDB Java driver that help you
22+
construct :ref:`Bson <bson>` objects. To learn more, see our :doc:`guide
23+
on builders </fundamentals/builders/>`.
2524

2625
Filters are the operations MongoDB uses to limit your results to what
2726
you want to see.

source/fundamentals/builders/indexes.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ Indexes Builders
1515
Overview
1616
--------
1717

18-
This guide shows you how to specify **indexes** using the Java Driver
19-
:doc:`builders </fundamentals/builders/>`. Index builders provide
20-
helper methods for the following types of indexes:
18+
In this guide, we show you how to specify **indexes** using the Java
19+
Driver :doc:`builders </fundamentals/builders/>`. Index builders provide
20+
helper methods for the following types of indexes:
2121

2222
- :ref:`Ascending Indexes <ascending-indexes>`
2323
- :ref:`Descending Indexes <descending-indexes>`

source/fundamentals/builders/projections.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Projections Builders
1515
Overview
1616
--------
1717

18+
In this guide, we show you how to specify **projections** using the Java
19+
Driver :doc:`builders </fundamentals/builders/>`.
20+
1821
MongoDB supports **field projection**, specifying which fields to include and exclude when returning results from a
1922
query. Projection in MongoDB follows some basic rules:
2023

source/fundamentals/builders/sort.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ examples of sort criteria are:
2525
* Earliest time of day to latest time of day
2626
* Alphabetical order by first name
2727

28-
Builders are classes provided by the MongoDB Java driver that help you construct
29-
:java-docs:`Bson <apidocs/bson/org/bson/conversions/Bson.html>` objects.
30-
To learn more, see our :doc:`guide on builders </fundamentals/builders/>`.
28+
Builders are classes provided by the MongoDB Java driver that help you
29+
construct :ref:`Bson <bson>` objects. To learn more, see our :doc:`guide
30+
on builders </fundamentals/builders/>`.
3131

3232
You should read this guide if you would like to use builders to specify sort
3333
criteria for your queries.

source/fundamentals/builders/updates.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Overview
1616
--------
1717

1818
This guide shows you how to specify **updates** using the Java Driver
19-
:doc:`builders </fundamentals/builders/>`. Update builders provide
20-
helper methods for the following types of updates:
19+
:doc:`builders </fundamentals/builders/>`.
20+
21+
Update builders provide helper methods for the following types of updates:
2122

2223
- :ref:`Field Updates <field_updates>`
2324
- :ref:`Array Updates <array_updates>`

0 commit comments

Comments
 (0)