Set up a sharded cluster of two replica sets, and call copydb on mongos:
var rsOpts = { oplogSize: 10 };
var st = new ShardingTest({shards : 1,
mongos : 1,
rs: rsOpts,
verbose : 0});
var mongos = st.s;
var test1 = mongos.getDB('test1');
var test2 = mongos.getDB('test2');
test1.getCollection('test').insert({foo: 'bar'});
jsTestLog('Test document on source db:');
printjson(test1.getCollection('test').findOne());
jsTestLog('copydb');
var result = mongos.getDB('admin').copyDatabase('test1', 'test2');
printjson(result);
assert.eq(result.ok, 1.0);
jsTestLog('Test document on destination db:');
printjson(test2.getCollection('test').findOne());
With mongod 2.4.9, the database is copied and copydb returns "ok": 1. With mongod
2.6.0-rc0 / hash 3779bf41, we get:
{
"ok" : 0,
"errmsg" : "couldn't connect to server shard1/localhost:4002,localhost:4003 (shard1/localhost:4002,localhost), connection attempt failed",
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("530758b3c9aea15f7b4c58bb")
}
}
The fault seems to be mongod's, since copydb works with old
mongod and new mongos. copydb always works if the shards aren't replica sets.
Description
"copydb" from mongos fails if the shards are replica sets running latest mongod.