The type code associated with a BSON element is a one-byte number which the MongoDB server's implementation interprets as a C++ signed char.
Whether or not the type code is a signed or unsigned char is usually not relevant, since all type codes except for MaxKey fall in the interval [0, 127]. However, the type code for MinKey is -1 (documented here). http://bsonspec.org/spec.html confusingly lists the MinKey type code as \xFF (the bit pattern 1111 1111) which would be 255 if interpreted as an unsigned char and -1 if interpreted as a twos complement signed char. This could lead a user to erroneously believe that {$type: 255} is a valid query, when in fact 255 is an invalid BSON type code.
http://bsonspec.org/spec.html should clarify that the type byte associated with a BSON element is a twos complement 8-bit signed number, and that the type code for MinKey is -1, not "\0xFF".
A/C
As a user, I understand that the type byte associated with a BSON element is a twos complement 8-bit signed char
As a user, i understand that the type code for minKey is -1
- related to
-
SERVER-8196 $type value should be signed extended
- Closed