var st = new ShardingTest({
other: {
rs: true,
rsOptions: {nodes: 2}
}
});
st.stopBalancer();
var mongos = st.s0;
var mongosAdmin = mongos.getDB('admin');
var dbName = 'foo';
var collectionName = 'bar';
var ns = dbName + '.' + collectionName;
var coll = mongos.getCollection(ns);
assert.commandWorked(mongosAdmin.runCommand({
enableSharding: coll.getDB().getName()
}));
assert.commandWorked(mongosAdmin.runCommand({
shardCollection: ns,
key: {_id: 1}
}));
st.printShardingStatus();
st.shard0.getCollection(ns).insert({});
assert.eq(null, st.shard0.getDB(dbName).getLastError());
assert.eq(1, st.shard0.getCollection(ns).count());
jsTest.log('Running cleanupOrphaned on ' + st.shard0);
response = st.shard0.getDB('admin').runCommand({cleanupOrphaned: ns});
assert.commandWorked(response);
assert.eq(null, response.stoppedAtKey);
assert.eq(
0, st.shard0.getCollection(ns).count(),
"cleanupOrphaned didn't delete orphan on empty shard.");