Skip to content

DOCS-8794: Document sort order for Object #3160

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions source/core/document.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
~~~~~~~~~~~

Expand Down
11 changes: 11 additions & 0 deletions source/reference/bson-type-comparison-order.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. versionadded:: 3.4

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behaviour wasn't changed at 3.4. Not sure what was the first version the behaviour introduced, but just never documented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that makes sense.

The comparison of BSON objects uses the following order:

#. Recursively compare key/value pairs in the order they appear within the BSON object.
#. Compare the :ref:`key field names <document-field-names>`.
#. 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
--------------------

Expand Down