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

Conversation

sindbach
Copy link
Contributor

@sindbach sindbach commented Dec 12, 2017

Based on
https://github.com/mongodb/mongo/blob/r3.4.10/src/mongo/bson/bsonobj.cpp#L105

applies to MongoDB v3.4 and v3.6


This change is Reviewable

Copy link
Contributor

@kallimachos kallimachos left a comment

Choose a reason for hiding this comment

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

Just a few suggestions on wording. Note also that lines should be wrapped at 80 chars.

Cheers,
Brian

Objects
-------

A comparison of two BSON objects using operators is performed using the following order :
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better with the active voice:

The comparison of BSON objects uses the following order:


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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Active voice:

Recursively compare key/value pairs in the order they appear within the BSON object.


#. The key/value pairs are recursively compared in the order of appearance within the BSON object.
#. Compare the :ref:`key field names <document-field-names>`.
#. If the key field name is equal, compare the value of the field.
Copy link
Contributor

Choose a reason for hiding this comment

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

Pluralize:

If the key field names are equal, compare the field values.

#. The key/value pairs are recursively compared in the order of appearance within the BSON object.
#. Compare the :ref:`key field names <document-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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@@ -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.

@@ -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.

Ah, that makes sense.

@schmalliso
Copy link
Contributor

Merged to master - thanks!

@schmalliso schmalliso closed this Jan 31, 2018
@schmalliso
Copy link
Contributor

Oh, and back-ported to 3.4 as well.

mongo-cr-bot pushed a commit that referenced this pull request May 18, 2023
* DOCSP-29495 Add Security Bug Form

* *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants