0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

make copyDatabase use admin db automatically SERVER-222

This commit is contained in:
Eliot Horowitz 2009-08-10 13:31:48 -04:00
parent d4961e1575
commit e44b51ee69
2 changed files with 27 additions and 1 deletions

20
jstests/copydb.js Normal file
View File

@ -0,0 +1,20 @@
a = db.getSisterDB( "copydb-test-a" );
b = db.getSisterDB( "copydb-test-b" );
a.dropDatabase();
b.dropDatabase();
a.foo.save( { a : 1 } );
assert.eq( 1 , a.foo.count() , "A" );
assert.eq( 0 , b.foo.count() , "B" );
a.copyDatabase( a._name , b._name );
assert.eq( 1 , a.foo.count() , "C" );
assert.eq( 1 , b.foo.count() , "D" );

View File

@ -42,6 +42,12 @@ DB.prototype.runCommand = function( obj ){
DB.prototype._dbCommand = DB.prototype.runCommand;
DB.prototype._adminCommand = function( obj ){
if ( this._name == "admin" )
return this.runCommand( obj );
return this.getSisterDB( "admin" ).runCommand( obj );
}
DB.prototype.addUser = function( username , pass ){
var c = this.getCollection( "system.users" );
@ -216,7 +222,7 @@ DB.prototype.copyDatabase = function(fromdb, todb, fromhost) {
assert( isString(todb) && todb.length );
fromhost = fromhost || "";
//this.resetIndexCache();
return this._dbCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );
return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );
}
/**