From 30d057a4622a24e1b5cd45589723796dac7f53e3 Mon Sep 17 00:00:00 2001 From: Wan Bachtiar Date: Tue, 12 Dec 2017 18:10:54 +1100 Subject: [PATCH 1/2] Added document sort order logic for Object comparison using operators --- source/core/document.txt | 2 ++ source/reference/bson-type-comparison-order.txt | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/source/core/document.txt b/source/core/document.txt index a6971e2b066..749c1b04bd6 100644 --- a/source/core/document.txt +++ b/source/core/document.txt @@ -65,6 +65,8 @@ The above fields have the following data types: - ``views`` holds a value of the *NumberLong* type. +.. _document-field-names: + Field Names ~~~~~~~~~~~ diff --git a/source/reference/bson-type-comparison-order.txt b/source/reference/bson-type-comparison-order.txt index 2471d691342..d4674c1ce7d 100644 --- a/source/reference/bson-type-comparison-order.txt +++ b/source/reference/bson-type-comparison-order.txt @@ -55,6 +55,17 @@ when comparing a field whose value is a single-element array (e.g. ``[ ``1`` and ``2``. A comparison of an empty array (e.g. ``[ ]``) treats the empty array as less than ``null`` or a missing field. +Objects +------- + +A comparison of two BSON objects using operators is performed using the following order : + +#. The key/value pairs are recursively compared in the order of appearance within the BSON object. +#. Compare the :ref:`key field names `. +#. If the key field name is equal, compare the value of the field. +#. If the value of the field is equal, compare the next key/value pair (back to step 1). This is where the length of the object matters, the object with the next non-null element is greater. + + Dates and Timestamps -------------------- From 4bcb45d3556f9cc7c0a2b52fc3adfabeaaefd4af Mon Sep 17 00:00:00 2001 From: Wan Bachtiar Date: Wed, 13 Dec 2017 17:25:38 +1100 Subject: [PATCH 2/2] Use active voice. --- source/reference/bson-type-comparison-order.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/reference/bson-type-comparison-order.txt b/source/reference/bson-type-comparison-order.txt index d4674c1ce7d..b8d99449e5c 100644 --- a/source/reference/bson-type-comparison-order.txt +++ b/source/reference/bson-type-comparison-order.txt @@ -58,12 +58,12 @@ the empty array as less than ``null`` or a missing field. Objects ------- -A comparison of two BSON objects using operators is performed using the following order : +The comparison of BSON objects uses the following order: -#. The key/value pairs are recursively compared in the order of appearance within the BSON object. +#. Recursively compare key/value pairs in the order they appear within the BSON object. #. Compare the :ref:`key field names `. -#. If the key field name is equal, compare the value of the field. -#. If the value of the field is equal, compare the next key/value pair (back to step 1). This is where the length of the object matters, the object with the next non-null element is greater. +#. If the key field names are equal, compare the field values. +#. If the field values are equal, compare the next key/value pair (return to step 1). An object without further pairs is lesser than an object with further pairs. Dates and Timestamps