Skip to content

Instantly share code, notes, and snippets.

@kevinAlbs
Created April 10, 2023 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinAlbs/fb9263040403a59c5610c6befdf59827 to your computer and use it in GitHub Desktop.
Save kevinAlbs/fb9263040403a59c5610c6befdf59827 to your computer and use it in GitHub Desktop.
// Test mongocryptd analysis of an insert to an int64 field.
// Run with: mongosh --port 27020 accept_int32_for_int64_field.js
// Sample output:
// Insert with NumberLong ... begin
// Insert with NumberLong ... end
// Insert with NumberInt ... begin
// MongoServerError: Cannot encrypt element of type int because schema requires that type is one of: [ long ]
const encryptionInformation = {
"type": 1,
"schema": {
"test.test": {
"escCollection": "enxcol_.test.esc",
"ecocCollection": "enxcol_.test.ecoc",
"fields": [
{
"keyId": UUID("b337ba84-68ec-4df5-b711-6e87bcfb9096"),
"path": "value",
"bsonType": "long",
"queries": {
"queryType": "equality",
"contention": 0
}
}
]
}
}
};
console.log("Insert with NumberLong ... begin")
db.runCommand({
"insert": "test",
"documents": [
{
"_id": 1,
"value": NumberLong("123")
}
],
"$db": "test",
"encryptionInformation": encryptionInformation
})
console.log("Insert with NumberLong ... end")
console.log("Insert with NumberInt ... begin")
db.runCommand({
"insert": "test",
"documents": [
{
"_id": 1,
"value": NumberInt("123")
}
],
"$db": "test",
"encryptionInformation": encryptionInformation
})
console.log("Insert with NumberInt ... end")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment