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:
parent
d4961e1575
commit
e44b51ee69
20
jstests/copydb.js
Normal file
20
jstests/copydb.js
Normal 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" );
|
||||
|
@ -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 } );
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user