jstests/replsets/v2_delta_oplog_entries.js
/**
 * Given a connection to a node, check that the most recent oplog entry for document with
 * 'expectedId' matches the type 'expectedOplogEntryType'.
 */
Given a connection to a node, check that the most recent oplog entry for document with
'expectedId' matches the type 'expectedOplogEntryType'.
Given a connection to a node check that the most recent oplog entry for document with ' expectedId ' matches the type ' expectedOplogEntryType ' .
function checkOplogEntry(node, expectedOplogEntryType, expectedId) {
    const oplog = node.getDB("local").getCollection("oplog.rs");
    const res = oplog
                    .find({
                        $and: [
                            {ns: primaryColl.getFullName()},
                            {$or: [{"o._id": expectedId}, {"o2._id": expectedId}]}
                        ]
                    })
                    .limit(1)
                    .hint({$natural: -1})  
                    .toArray();
    assert.eq(res.length, 1);
    const oplogEntry = res[0];
    if (expectedOplogEntryType === kExpectDeltaEntry) {
        assert.eq(oplogEntry.op, "u");
        assert.eq(oplogEntry.o.$v, 2, oplogEntry);
        assert.eq(typeof (oplogEntry.o.diff), "object", oplogEntry);
        assert.eq(oplogEntry.o2._id, expectedId);
        assert.eq(Object.keys(oplogEntry.o), ["$v", "diff"]);
        for (let key of Object.keys(oplogEntry.o.diff)) {
            assert.contains(key[0], ["i", "u", "s", "d"]);
        }
    } else if (expectedOplogEntryType === kExpectReplacementEntry) {
        assert.eq(oplogEntry.op, "u");
        assert.eq(oplogEntry.o.hasOwnProperty("$v"), false, oplogEntry);
    } else if (expectedOplogEntryType == kExpectNoUpdateEntry) {
        assert.eq(oplogEntry.op, "i");
        assert.eq(oplogEntry.o._id, expectedId);
    }
}
function checkOplogEntry ( node , expectedOplogEntryType , expectedId ) { const oplog = node . getDB ( "local" ) . getCollection ( "oplog.rs" ) ; const res = oplog . find ( { $and : [ { ns : primaryColl . getFullName ( ) } , { $or : [ { "o._id" : expectedId } , { "o2._id" : expectedId } ] } ] } ) . limit ( 1 ) . hint ( { $natural : - 1 } ) . toArray ( ) ; assert . eq ( res . length , 1 ) ; const oplogEntry = res [ 0 ] ; if ( expectedOplogEntryType === kExpectDeltaEntry ) { assert . eq ( oplogEntry . op , "u" ) ; assert . eq ( oplogEntry . o . $v , 2 , oplogEntry ) ; assert . eq ( typeof ( oplogEntry . o . diff ) , "object" , oplogEntry ) ; assert . eq ( oplogEntry . o2 . _id , expectedId ) ; assert . eq ( Object . keys ( oplogEntry . o ) , [ "$v" , "diff" ] ) ; for ( let key of Object . keys ( oplogEntry . o . diff ) ) { assert . contains ( key [ 0 ] , [ "i" , "u" , "s" , "d" ] ) ; } } else if ( expectedOplogEntryType === kExpectReplacementEntry ) { assert . eq ( oplogEntry . op , "u" ) ; assert . eq ( oplogEntry . o . hasOwnProperty ( "$v" ) , false , oplogEntry ) ; } else if ( expectedOplogEntryType == kExpectNoUpdateEntry ) { assert . eq ( oplogEntry . op , "i" ) ; assert . eq ( oplogEntry . o . _id , expectedId ) ; } }
Given a connection to a node, check that the most recent oplog entry for document with
 'expectedId' matches the type 'expectedOplogEntryType'.
Given a connection to a node check that the most recent oplog entry for document with ' expectedId ' matches the type ' expectedOplogEntryType ' .
// Reverse scan, so we get the most recent entry. // Check that the oplog entry's _id field is for the document we updated. // Do some cursory/weak checks about the format of the 'o' field.