function moveChunk(st, fromMongod, toMongod, epoch) {
var chunk = st.s.getDB("config").chunks.findOne({shard: fromMongod.shardName});
assert(chunk, "no chunks on shard to move");
epoch = epoch || chunk.lastmodEpoch;
var cmd = {
moveChunk: coll + "",
from: fromMongod.host,
to: toMongod.host,
fromShard: fromMongod.shardName,
toShard: toMongod.shardName,
min: {x: chunk.min.x},
max: {x: chunk.max.x},
maxChunkSizeBytes: 52428800,
shardId: chunk._id,
configdb: st.config0.host,
secondaryThrottle: true,
waitForDelete: true,
maxTimeMS: 0,
epoch: epoch
};
assert.commandWorked(fromMongod.adminCommand(cmd), "moveChunk worked " + tojson(epoch));
}
var st = new ShardingTest({name: "epoch", shards: 2, chunkSize: 1});
st.stopBalancer();
var configDB = st.s.getDB("config");
var testDB = st.s.getDB("test");
var collName = "epoch";
var coll = testDB[collName];
configDB.adminCommand({enableSharding: "test"});
configDB.adminCommand({movePrimary: "test", to: "shard0000"});
configDB.adminCommand({shardCollection: coll + "", key: {x: 1}});
assert.commandWorked(
configDB.adminCommand({split: coll + "", middle: {x: 100}}),
"split");
assert.commandWorked(
configDB.adminCommand({moveChunk: coll + "", find: {x: 100}, to: "shard0001"}),
"moveChunk");
var collectionDoc = configDB.collections.findOne({_id: coll + ""});
var lastmodEpoch = collectionDoc.lastmodEpoch;
moveChunk(st, st.d0, st.d1, "abc"); moveChunk(st, st.d1, st.d0, 12345); moveChunk(st, st.d0, st.d1, lastmodEpoch);
st.stop();