jstests/aggregation/expressions/expression_set_field.js
// Test that $setField and $unsetField both correctly unset the 'field' in all documents in 'coll'.
Test that $setField and $unsetField both correctly unset the 'field' in all documents in 'coll'.
Test that $setField and $unsetField both correctly unset the ' field ' in all documents in ' coll ' .
function assertUnsetFieldInRootDoc(field) {
    assertPipelineResultsEq(
        [{
            $project: {
                _id: 1,
                test: {$setField: {field: {$const: field}, input: "$$ROOT", value: "$$REMOVE"}}
            }
        }],
        getTestCasesForUnset(field));
    assertPipelineResultsEq(
        [{$project: {_id: 1, test: {$unsetField: {field: {$const: field}, input: "$$ROOT"}}}}],
        getTestCasesForUnset(field));
}
function assertUnsetFieldInRootDoc ( field ) { assertPipelineResultsEq ( [ { $project : { _id : 1 , test : { $setField : { field : { $const : field } , input : "$$ROOT" , value : "$$REMOVE" } } } } ] , getTestCasesForUnset ( field ) ) ; assertPipelineResultsEq ( [ { $project : { _id : 1 , test : { $unsetField : { field : { $const : field } , input : "$$ROOT" } } } } ] , getTestCasesForUnset ( field ) ) ; }
Test that $setField and $unsetField both correctly unset the 'field' in all documents in 'coll'.
Test that $setField and $unsetField both correctly unset the ' field ' in all documents in ' coll ' .
// Wrap 'field' argument to $setField in $const to allow test cases containing dots and dollars. // Test $unsetField alias as well.