The options min and max of the encryptedFields query must have the exact same type as the bsonType that is configured. This constraint is too strict as the server is able to convert from int to long.
Issue: an encryptedFieldsMap is specified with bsonType=long and queries.min is an int,
[ 'path' => 'age', 'bsonType' => 'long', 'keyId' => null, 'queries' => [['queryType' => 'range', 'min' => 1, 'max' => PHP_INT_MAX-10]] ],
then the following exception is thrown:
mongocryptd error: Range field type 'long' does not match the min value type 'int'
The fix is to transmit an Int64 explicitly.
[ 'path' => 'age', 'bsonType' => 'long', 'keyId' => null, 'queries' => [['queryType' => 'range', 'min' => new MongoDB\BSON\Int64(1), 'max' => new MongoDB\BSON\Int64(PHP_INT_MAX-10)]] ],
Which isn't very practical.
Solution: automatically convert the value into the expected bsonType when possible in the Manager driver options, and in the createEncryptedCollection options.