Skip to content

Commit

Permalink
make copyDatabase use admin db automatically SERVER-222
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Aug 10, 2009
1 parent d4961e1 commit e44b51e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions jstests/copydb.js
Original file line number Original file line Diff line number Diff line change
@@ -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" );

8 changes: 7 additions & 1 deletion shell/db.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ DB.prototype.runCommand = function( obj ){


DB.prototype._dbCommand = DB.prototype.runCommand; 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 ){ DB.prototype.addUser = function( username , pass ){
var c = this.getCollection( "system.users" ); var c = this.getCollection( "system.users" );


Expand Down Expand Up @@ -216,7 +222,7 @@ DB.prototype.copyDatabase = function(fromdb, todb, fromhost) {
assert( isString(todb) && todb.length ); assert( isString(todb) && todb.length );
fromhost = fromhost || ""; fromhost = fromhost || "";
//this.resetIndexCache(); //this.resetIndexCache();
return this._dbCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } ); return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );
} }


/** /**
Expand Down

0 comments on commit e44b51e

Please sign in to comment.