Skip to content

Commit

Permalink
added getSiblingDB SERVER-2159
Browse files Browse the repository at this point in the history
  • Loading branch information
erh committed Nov 30, 2010
1 parent 37512ba commit 1808b56
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions jstests/apitest_db.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,8 @@ assert( asserted, "should have asserted" );

dd( "g" );



assert.eq( "foo" , db.getSisterDB( "foo" ).getName() )
assert.eq( "foo" , db.getSiblingDB( "foo" ).getName() )

14 changes: 8 additions & 6 deletions shell/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ DB.prototype.getMongo = function(){
return this._mongo;
}

DB.prototype.getSisterDB = function( name ){
DB.prototype.getSiblingDB = function( name ){
return this.getMongo().getDB( name );
}

DB.prototype.getSisterDB = DB.prototype.getSiblingDB;

DB.prototype.getName = function(){
return this._name;
}
Expand Down Expand Up @@ -49,7 +51,7 @@ 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 );
return this.getSiblingDB( "admin" ).runCommand( obj );
}

DB.prototype._adminCommand = DB.prototype.adminCommand; // alias old name
Expand Down Expand Up @@ -289,7 +291,7 @@ DB.prototype.help = function() {
print("\tdb.getProfilingLevel() - deprecated");
print("\tdb.getProfilingStatus() - returns if profiling is on and slow threshold ");
print("\tdb.getReplicationInfo()");
print("\tdb.getSisterDB(name) get the db at the same server as this one");
print("\tdb.getSiblingDB(name) get the db at the same server as this one");
print("\tdb.isMaster() check replica primary status");
print("\tdb.killOp(opid) kills the current operation in the db");
print("\tdb.listCommands() lists all the db commands");
Expand Down Expand Up @@ -591,7 +593,7 @@ DB.tsToSeconds = function(x){
* of date than that, it can't recover without a complete resync
*/
DB.prototype.getReplicationInfo = function() {
var db = this.getSisterDB("local");
var db = this.getSiblingDB("local");

var result = { };
var oplog;
Expand Down Expand Up @@ -698,7 +700,7 @@ DB.prototype.printSlaveReplicationInfo = function() {
}
};

var L = this.getSisterDB("local");
var L = this.getSiblingDB("local");
if( L.sources.count() != 0 ) {
L.sources.find().forEach(g);
}
Expand Down Expand Up @@ -754,7 +756,7 @@ DB.prototype.listCommands = function(){
}

DB.prototype.printShardingStatus = function(){
printShardingStatus( this.getSisterDB( "config" ) );
printShardingStatus( this.getSiblingDB( "config" ) );
}

DB.autocomplete = function(obj){
Expand Down
14 changes: 8 additions & 6 deletions shell/mongo_vstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,10 +1474,12 @@ const StringData _jscode_raw_db =
"return this._mongo;\n"
"}\n"
"\n"
"DB.prototype.getSisterDB = function( name ){\n"
"DB.prototype.getSiblingDB = function( name ){\n"
"return this.getMongo().getDB( name );\n"
"}\n"
"\n"
"DB.prototype.getSisterDB = DB.prototype.getSiblingDB;\n"
"\n"
"DB.prototype.getName = function(){\n"
"return this._name;\n"
"}\n"
Expand Down Expand Up @@ -1511,7 +1513,7 @@ const StringData _jscode_raw_db =
"DB.prototype.adminCommand = function( obj ){\n"
"if ( this._name == \"admin\" )\n"
"return this.runCommand( obj );\n"
"return this.getSisterDB( \"admin\" ).runCommand( obj );\n"
"return this.getSiblingDB( \"admin\" ).runCommand( obj );\n"
"}\n"
"\n"
"DB.prototype._adminCommand = DB.prototype.adminCommand; // alias old name\n"
Expand Down Expand Up @@ -1751,7 +1753,7 @@ const StringData _jscode_raw_db =
"print(\"\\tdb.getProfilingLevel() - deprecated\");\n"
"print(\"\\tdb.getProfilingStatus() - returns if profiling is on and slow threshold \");\n"
"print(\"\\tdb.getReplicationInfo()\");\n"
"print(\"\\tdb.getSisterDB(name) get the db at the same server as this one\");\n"
"print(\"\\tdb.getSiblingDB(name) get the db at the same server as this one\");\n"
"print(\"\\tdb.isMaster() check replica primary status\");\n"
"print(\"\\tdb.killOp(opid) kills the current operation in the db\");\n"
"print(\"\\tdb.listCommands() lists all the db commands\");\n"
Expand Down Expand Up @@ -2053,7 +2055,7 @@ const StringData _jscode_raw_db =
"* of date than that, it can't recover without a complete resync\n"
"*/\n"
"DB.prototype.getReplicationInfo = function() {\n"
"var db = this.getSisterDB(\"local\");\n"
"var db = this.getSiblingDB(\"local\");\n"
"\n"
"var result = { };\n"
"var oplog;\n"
Expand Down Expand Up @@ -2160,7 +2162,7 @@ const StringData _jscode_raw_db =
"}\n"
"};\n"
"\n"
"var L = this.getSisterDB(\"local\");\n"
"var L = this.getSiblingDB(\"local\");\n"
"if( L.sources.count() != 0 ) {\n"
"L.sources.find().forEach(g);\n"
"}\n"
Expand Down Expand Up @@ -2216,7 +2218,7 @@ const StringData _jscode_raw_db =
"}\n"
"\n"
"DB.prototype.printShardingStatus = function(){\n"
"printShardingStatus( this.getSisterDB( \"config\" ) );\n"
"printShardingStatus( this.getSiblingDB( \"config\" ) );\n"
"}\n"
"\n"
"DB.autocomplete = function(obj){\n"
Expand Down

0 comments on commit 1808b56

Please sign in to comment.