jstests/core/write_change_stream_pit_preimage.js
// Tests the pre-images recording behavior in capped collections.
Tests the pre-images recording behavior in capped collections.
Tests the pre - images recording behavior in capped collections .
function testPreImageRecordingInCappedCollection({updateDocFunc, replaceDocFunc}) {
    const collWithPreImages = assertDropAndRecreateCollection(
        testDB,
        "coll_with_pre_images",
        {changeStreamPreAndPostImages: {enabled: true}, capped: true, size: 1, max: 1});
    assertChangeStreamPreAndPostImagesCollectionOptionIsEnabled(testDB,
                                                                collWithPreImages.getName());
    const collWithNoPreImages = assertDropAndRecreateCollection(
        testDB, "coll_with_no_pre_images", {capped: true, size: 1, max: 1});
    assertChangeStreamPreAndPostImagesCollectionOptionIsAbsent(testDB,
                                                               collWithNoPreImages.getName());
    assertNoPreImageWrittenForOps(testDB, function() {
        assert.commandWorked(collWithNoPreImages.insert(originalDoc));
        updateDocFunc(collWithNoPreImages);
        assert.eq(collWithNoPreImages.find().itcount(), 1);
        assert.commandWorked(collWithNoPreImages.insert({x: "abcd"}));
    });
    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() {
        assert.commandWorked(collWithPreImages.insert({x: "abcd"}));
    }, [replacedDoc]);
}
function testPreImageRecordingInCappedCollection ( { updateDocFunc , replaceDocFunc } ) { const collWithPreImages = assertDropAndRecreateCollection ( testDB , "coll_with_pre_images" , { changeStreamPreAndPostImages : { enabled : true } , capped : true , size : 1 , max : 1 } ) ; assertChangeStreamPreAndPostImagesCollectionOptionIsEnabled ( testDB , collWithPreImages . getName ( ) ) ; const collWithNoPreImages = assertDropAndRecreateCollection ( testDB , "coll_with_no_pre_images" , { capped : true , size : 1 , max : 1 } ) ; assertChangeStreamPreAndPostImagesCollectionOptionIsAbsent ( testDB , collWithNoPreImages . getName ( ) ) ; assertNoPreImageWrittenForOps ( testDB , function ( ) { assert . commandWorked ( collWithNoPreImages . insert ( originalDoc ) ) ; updateDocFunc ( collWithNoPreImages ) ; assert . eq ( collWithNoPreImages . find ( ) . itcount ( ) , 1 ) ; assert . commandWorked ( collWithNoPreImages . insert ( { x : "abcd" } ) ) ; } ) ; 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 ( ) { assert . commandWorked ( collWithPreImages . insert ( { x : "abcd" } ) ) ; } , [ replacedDoc ] ) ; }
Tests the pre-images recording behavior in capped collections.
Tests the pre - images recording behavior in 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 and replace commands. // Document removal is not allowed on a capped collection, perform an insert command // instead. // Verify that no pre-image is recorded, when performing an insert command on 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. // Trigger a delete operation from the capped collection by inserting a new document.