Interestingly if I add the field ‘byteOrder’ to the aggregation I get an error saying the field doesn’t exist for the operator $convert.
{
"$addFields": {
"hex_id": {
"$convert": {
"input": {
"$convert": {
"input": {"$toInt": "$int_id"},
"to": "binData",
"byteOrder": "little",
"onError": "Invalid binary.",
"onNull": "Missing value.",
}
},
"to": "string",
"format": "hex",
"byteOrder": "little",
"onError": "Invalid hex.",
"onNull": "Missing value.",
}
}
}
}
The Error:
pymongo.errors.OperationFailure: Invalid $addFields :: caused by :: $convert found an unknown argument: byteOrder, full error: {‘ok’: 0.0, ‘errmsg’: ‘Invalid $addFields :: caused by :: $convert found an unknown argument: byteOrder’, ‘code’: 9, ‘codeName’: ‘FailedToParse’, ‘$clusterTime’: {‘clusterTime’: Timestamp(1743617331, 1), ‘signature’: {‘hash’: b’ht\xf3\xbe\xca\x9f\xfd\x07|\x87\x8dkh\x94\x06\xdbf\x9e\xe6\x00’, ‘keyId’: 7488712192850657286}}, ‘operationTime’: Timestamp(1743617331, 1)}
This is unexpected as this field is clearly documented for the $convert operator. I have upgraded to pymongo latest and still get the same error and this error also triggers regardless of which $convert the byteOrder field is added to.