Where in the MongoDB source code is the comparator implementation for BSON objects?

Hello everyone,

I’m trying to figure out how MongoDB implements certain bits and pieces. I’m currently stuck at the ordering of documents. The MongoDB documentation for example states that arrays of size 1 sort as if the contents were unpacked. Also, arrays use their minimum element for ascending sort, and their maximum for descending.

I tried to find the relevant parts in the code (v6.1 branch on git), but I think I took a wrong turn somewhere. bsonelement.cpp specifies BSONElement::wocompare, but while this method is used a lot throughout the source code, its implementation doesn’t seem to correspond to the behaviour mentioned in the documentation at all. It treats arrays and objects the same (there is no search for the maximum/minimum element for example).

By a similar argument, in key_string.cpp, BuilderBase<BufferT>::_appendArray only appends the array values one by one. This is consistent with wocompare, but something entirely different than what the MongoDB documentation says.

Where can I find the actual comparator implementation that implements the comparison as stated in the documentation?