jstests/core/write_change_stream_pit_preimage.js
// Tests the pre-images recording behavior in non-capped collections.
Tests the pre-images recording behavior in non-capped collections.
Tests the pre - images recording behavior in non - capped collections .
function testPreImageRecordingInNonCappedCollection(
    {updateDocFunc, replaceDocFunc, removeDocFunc}) {
    const collWithPreImages = assertDropAndRecreateCollection(
        testDB, "coll_with_pre_images", {changeStreamPreAndPostImages: {enabled: true}});
    assertChangeStreamPreAndPostImagesCollectionOptionIsEnabled(testDB,
                                                                collWithPreImages.getName());
    const collWithNoPreImages = assertDropAndRecreateCollection(testDB, "coll_with_no_pre_images");
    assertChangeStreamPreAndPostImagesCollectionOptionIsAbsent(testDB,
                                                               collWithNoPreImages.getName());
    assertNoPreImageWrittenForOps(testDB, function() {
        assert.commandWorked(collWithNoPreImages.insert(originalDoc));
        updateDocFunc(collWithNoPreImages);
        replaceDocFunc(collWithNoPreImages);
        assert.eq(collWithNoPreImages.find().itcount(), 1);
        removeDocFunc(collWithNoPreImages);
    });
    assertNoPreImageWrittenForOps(testDB, function() {
        assert.commandWorked(collWithPreImages.insert(originalDoc));
        assert.eq(collWithPreImages.find().itcount(), 1);
    });
    assertPreImagesWrittenForOps(testDB, function() {
        updateDocFunc(collWithPreImages);
    }, [originalDoc]);
    assertPreImagesWrittenForOps(testDB, function() {
        replaceDocFunc(collWithPreImages);
    }, [updatedDoc]);
    assertPreImagesWrittenForOps(testDB, function() {
        removeDocFunc(collWithPreImages);
    }, [replacedDoc]);
}
function testPreImageRecordingInNonCappedCollection ( { updateDocFunc , replaceDocFunc , removeDocFunc } ) { const collWithPreImages = assertDropAndRecreateCollection ( testDB , "coll_with_pre_images" , { changeStreamPreAndPostImages : { enabled : true } } ) ; assertChangeStreamPreAndPostImagesCollectionOptionIsEnabled ( testDB , collWithPreImages . getName ( ) ) ; const collWithNoPreImages = assertDropAndRecreateCollection ( testDB , "coll_with_no_pre_images" ) ; assertChangeStreamPreAndPostImagesCollectionOptionIsAbsent ( testDB , collWithNoPreImages . getName ( ) ) ; assertNoPreImageWrittenForOps ( testDB , function ( ) { assert . commandWorked ( collWithNoPreImages . insert ( originalDoc ) ) ; updateDocFunc ( collWithNoPreImages ) ; replaceDocFunc ( collWithNoPreImages ) ; assert . eq ( collWithNoPreImages . find ( ) . itcount ( ) , 1 ) ; removeDocFunc ( collWithNoPreImages ) ; } ) ; assertNoPreImageWrittenForOps ( testDB , function ( ) { assert . commandWorked ( collWithPreImages . insert ( originalDoc ) ) ; assert . eq ( collWithPreImages . find ( ) . itcount ( ) , 1 ) ; } ) ; assertPreImagesWrittenForOps ( testDB , function ( ) { updateDocFunc ( collWithPreImages ) ; } , [ originalDoc ] ) ; assertPreImagesWrittenForOps ( testDB , function ( ) { replaceDocFunc ( collWithPreImages ) ; } , [ updatedDoc ] ) ; assertPreImagesWrittenForOps ( testDB , function ( ) { removeDocFunc ( collWithPreImages ) ; } , [ replacedDoc ] ) ; }
Tests the pre-images recording behavior in non-capped collections.
Tests the pre - images recording behavior in non - capped collections .
// Verify that no pre-image is recorded, when performing writes to the collection, that doesn't // have 'changeStreamPreAndPostImages' enabled. // Perform the insert, update, replace and delete commands. // Verify that no pre-image is recorded, when performing an insert command into the collection, // that has 'changeStreamPreAndPostImages' enabled. // Verify that one pre-image is recorded, when performing an update command on the collection, // that has 'changeStreamPreAndPostImages' enabled. // Perform an update modification. // Verify that one pre-image is recorded, when performing a replace command on the collection, // that has 'changeStreamPreAndPostImages' enabled. // Perform a full-document replacement. // Verify that one pre-image is recorded, when performing a delete command on the collection, // that has 'changeStreamPreAndPostImages' enabled. // Perform a document removal.