Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make copyDatabase use admin db automatically SERVER-222

  • Loading branch information...
commit e44b51ee69288b7fc1e04da3d8f25cb28c931c68 1 parent d4961e1
@erh erh authored
Showing with 27 additions and 1 deletion.
  1. +20 −0 jstests/copydb.js
  2. +7 −1 shell/db.js
View
20 jstests/copydb.js
@@ -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
8 shell/db.js
@@ -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 } );
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.