Hi, the simplest way to clear the oplog is to resize it. See
. Here is a snippet of code which may help:
print("Starting oplog resize, before:");
rs.printReplicationInfo();
//
// Save the last oplog record and resize the log
//
db = db.getSiblingDB('local');
db.tempOplogRec.drop();
db.tempOplogRec.save( db.oplog.rs.find( { }, { ts: 1, h: 1 } ).sort( {$natural : -1} ).limit(1).next() )
if (db.oplog.rs.count() == 0)
{ throw new Error("Save of last oplog record failed, aborting");
};
db.oplog.rs.drop()
db.runCommand( { create: "oplog.rs", capped: true, size: (newSize * 1024 * 1024 * 1024) } ) db.oplog.rs.save( db.tempOplogRec.findOne() )
print("Oplog resized to " + newSize + "GB");
print("Done with oplog resize, after:");
rs.printReplicationInfo();
}
I strongly suggest you practice on a throwaway replica set first! You will need to perform a rolling shutdown of the replica set.