Skip to content

[Java] - Improve Sort Builder page sample data #491

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

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Changes from all commits
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
45 changes: 25 additions & 20 deletions source/fundamentals/builders/sort.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
Sorts Builders
==============

.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference

.. meta::
:keywords: code example, sorting

.. contents:: On this page
:local:
Expand Down Expand Up @@ -43,12 +48,12 @@ contains the following documents:

.. code-block:: json

{"_id": 1, "letter": "c", "food": "coffee with milk"}
{"_id": 3, "letter": "a", "food": "maple syrup"}
{"_id": 4, "letter": "b", "food": "coffee with sugar"}
{"_id": 5, "letter": "a", "food": "milk and cookies"}
{"_id": 2, "letter": "a", "food": "donuts and coffee"}
{"_id": 6, "letter": "c", "food": "maple donut"}
{ "_id": 1, "date": "2022-01-03", "orderTotal": 17.86, "description": "1/2 lb cream cheese and 1 dozen bagels" },
{ "_id": 2, "date": "2022-01-11", "orderTotal": 83.87, "description": "two medium strawberry birthday cakes" },
{ "_id": 3, "date": "2022-01-11", "orderTotal": 19.49, "description": "1 dozen strawberry cupcakes" },
{ "_id": 4, "date": "2022-01-15", "orderTotal": 43.62, "description": "2 chicken lunches and a diet coke" },
{ "_id": 5, "date": "2022-01-23", "orderTotal": 10.99, "description": "1 bagel, 1 orange juice, 1 muffin" },
{ "_id": 6, "date": "2022-01-23", "orderTotal": 60.31, "description": "one large strawberry and chocolate cake" }

The Sorts Class
---------------
Expand Down Expand Up @@ -92,9 +97,9 @@ The output of the preceding example should look something like this:
.. code-block:: json
:copyable: false

{"_id": 1, "letter": "c", "food": "coffee with milk"}
{"_id": 2, "letter": "a", "food": "donuts and coffee"}
{"_id": 3, "letter": "a", "food": "maple syrup"}
{ "_id": 1, "date": "2022-01-03", "orderTotal": 17.86, "description": "1/2 lb cream cheese and 1 dozen bagels" }
{ "_id": 2, "date": "2022-01-11", "orderTotal": 83.87, "description": "two medium strawberry birthday cakes" }
{ "_id": 3, "date": "2022-01-11", "orderTotal": 19.49, "description": "1 dozen strawberry cupcakes" }
...

Descending
Expand All @@ -120,9 +125,9 @@ The preceding example should output something like this:
.. code-block:: json
:copyable: false

{"_id": 6, "letter": "c", "food": "maple donut"}
{"_id": 5, "letter": "a", "food": "milk and cookies"}
{"_id": 4, "letter": "b", "food": "coffee with sugar"}
{ "_id": 6, "date": "2022-01-23", "orderTotal": 60.31, "description": "one large strawberry and chocolate cake" }
{ "_id": 5, "date": "2022-01-23", "orderTotal": 10.99, "description": "1 bagel, 1 orange juice, 1 muffin" }
{ "_id": 4, "date": "2022-01-15", "orderTotal": 43.62, "description": "2 chicken lunches and a diet coke" }
...

Combining Sort Criteria
Expand All @@ -146,20 +151,20 @@ on the ``letter`` field, and in the event of a tie, ascending order on the

// <MongoCollection setup code here>

Bson orderBySort = orderBy(descending("letter"), ascending("_id"));
Bson orderBySort = orderBy(descending("date"), ascending("orderTotal"));
collection.find().sort(orderBySort);

The output of the preceding example should look something like this:

.. code-block:: json
:copyable: false

{"_id": 1, "letter": "c", "food": "coffee with milk"}
{"_id": 6, "letter": "c", "food": "maple donut"}
{"_id": 4, "letter": "b", "food": "coffee with sugar"}
{"_id": 2, "letter": "a", "food": "donuts and coffee"}
{"_id": 3, "letter": "a", "food": "maple syrup"}
{"_id": 5, "letter": "a", "food": "milk and cookies"}
{ "_id": 5, "date": "2022-01-23", "orderTotal": 10.99, "description": "1 bagel, 1 orange juice, 1 muffin" }
{ "_id": 6, "date": "2022-01-23", "orderTotal": 60.31, "description": "one large strawberry and chocolate cake" }
{ "_id": 4, "date": "2022-01-15", "orderTotal": 43.62, "description": "2 chicken lunches and a diet coke" }
{ "_id": 3, "date": "2022-01-11", "orderTotal": 19.49, "description": "1 dozen strawberry cupcakes" }
{ "_id": 2, "date": "2022-01-11", "orderTotal": 83.87, "description": "two medium strawberry birthday cakes" }
{ "_id": 1, "date": "2022-01-03", "orderTotal": 17.86, "description": "1/2 lb cream cheese and 1 dozen bagels" }

Text Score
----------
Expand Down