jstests/fle2/implicit_schema_validation.js
// This assumes 'coll' was created encrypted fields specified in 'sampleEncryptedFields'.
This assumes 'coll' was created encrypted fields specified in 'sampleEncryptedFields'.
This assumes ' coll ' was created encrypted fields specified in ' sampleEncryptedFields ' .
function positiveUpdateTests(coll, invert = false) {
    function assertExpectedResult(result) {
        if (invert) {
            assert.commandFailedWithCode(result, ErrorCodes.DocumentValidationFailure);
        } else {
            assert.commandWorked(result);
        }
    }
    assert.commandWorked(coll.insert({
        test_id: 0,
        firstName: validEncryptedString,
        a: {
            b: {
                c: validEncryptedInt,
                d: validEncryptedInt,
            },
            x: {
                y: validEncryptedString,
            }
        }
    }));
    jsTestLog("test unset & set of encrypted field");
    assertExpectedResult(coll.update({"test_id": 0}, {$unset: {"firstName": ""}}));
    assertExpectedResult(coll.update({"test_id": 0}, {$set: {"firstName": validEncryptedString}}));
    assertExpectedResult(
        coll.update({"test_id": 0}, {$set: {"a": {"x": {"y": validEncryptedString}}}}));
    assertExpectedResult(coll.update({"test_id": 0}, {$set: {"a.x": {"y": validEncryptedString}}}));
    jsTestLog("test updating prefix of encrypted field with non-array value");
    assertExpectedResult(coll.update({"test_id": 0}, {$set: {"a.b": 1}}));
    assertExpectedResult(coll.update({"test_id": 0}, {$set: {"a.x": {"z": 42}}}));
}
function positiveUpdateTests ( coll , invert = false ) { function assertExpectedResult ( result ) { if ( invert ) { assert . commandFailedWithCode ( result , ErrorCodes . DocumentValidationFailure ) ; } else { assert . commandWorked ( result ) ; } } assert . commandWorked ( coll . insert ( { test_id : 0 , firstName : validEncryptedString , a : { b : { c : validEncryptedInt , d : validEncryptedInt , } , x : { y : validEncryptedString , } } } ) ) ; jsTestLog ( "test unset & set of encrypted field" ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $unset : { "firstName" : "" } } ) ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $set : { "firstName" : validEncryptedString } } ) ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $set : { "a" : { "x" : { "y" : validEncryptedString } } } } ) ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $set : { "a.x" : { "y" : validEncryptedString } } } ) ) ; jsTestLog ( "test updating prefix of encrypted field with non-array value" ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $set : { "a.b" : 1 } } ) ) ; assertExpectedResult ( coll . update ( { "test_id" : 0 } , { $set : { "a.x" : { "z" : 42 } } } ) ) ; }
This assumes 'coll' was created encrypted fields specified in 'sampleEncryptedFields'.
This assumes ' coll ' was created encrypted fields specified in ' sampleEncryptedFields ' .
// first, insert a valid document to update