jstests/libs/change_stream_util.js
// Returns the pre-images written while performing the write operations.
Returns the pre-images written while performing the write operations.
Returns the pre - images written while performing the write operations .
function preImagesForOps(db, writeOps) {
    const preImagesColl = getPreImagesCollection(db);
    const preImagesCollSortSpec = {"_id.ts": 1, "_id.applyOpsIndex": 1};
    const preImageIdsBefore =
        preImagesColl.find({}, {}).sort(preImagesCollSortSpec).allowDiskUse().toArray();
    const lastPreImageId = (preImageIdsBefore.length > 0)
        ? preImageIdsBefore[preImageIdsBefore.length - 1]._id
        : undefined;
    writeOps();
    const preImageFilter = lastPreImageId ? {"_id.ts": {$gt: lastPreImageId.ts}} : {};
    const result =
        preImagesColl.find(preImageFilter).sort(preImagesCollSortSpec).allowDiskUse().toArray();
    assert(lastPreImageId === undefined || preImagesColl.find({_id: lastPreImageId}).itcount() == 1,
           "Last pre-image document has been removed by the pre-image purging job.");
    return result;
}
function preImagesForOps ( db , writeOps ) { const preImagesColl = getPreImagesCollection ( db ) ; const preImagesCollSortSpec = { "_id.ts" : 1 , "_id.applyOpsIndex" : 1 } ; const preImageIdsBefore = preImagesColl . find ( { } , { } ) . sort ( preImagesCollSortSpec ) . allowDiskUse ( ) . toArray ( ) ; const lastPreImageId = ( preImageIdsBefore . length > 0 ) ? preImageIdsBefore [ preImageIdsBefore . length - 1 ] . _id : undefined ; writeOps ( ) ; const preImageFilter = lastPreImageId ? { "_id.ts" : { $gt : lastPreImageId . ts } } : { } ; const result = preImagesColl . find ( preImageFilter ) . sort ( preImagesCollSortSpec ) . allowDiskUse ( ) . toArray ( ) ; assert ( lastPreImageId === undefined || preImagesColl . find ( { _id : lastPreImageId } ) . itcount ( ) == 1 , "Last pre-image document has been removed by the pre-image purging job." ) ; return result ; }
Returns the pre-images written while performing the write operations.
Returns the pre - images written while performing the write operations .
// Determine the id of the last pre-image document written to be able to determine the pre-image // documents written by 'writeOps()'. The pre-image purging job may concurrently remove some // pre-image documents while this function is executing. // Perform the write operations. // Return only newly written pre-images. // Verify that the result is correct by checking if the last pre-image still exists. However, if // no pre-image document existed before 'writeOps()' invocation, the result may be incorrect.