Mongodb why do we need getSisterDB

During the game, using the mognodb console help, I found the db.getSisterDB() method.

And I'm curious what the purpose of this method is. Looking at mongodb documentation and a quick google search did not give satisfactory results.

Typing db.getSisterDb.help generates an error, and typing db.getSisterDB gives the following definition for this method:

 function ( name ){ return this.getMongo().getDB( name ); } 

which suggests that this is just a wrapper around getDB . My guess is that it is used to access databases in a replica set, but I would like to listen to someone who can give me a more detailed explanation.

+7
mongodb
source share
2 answers

In the shell, db is a reference to the current database. If you want to request another database in the same instance of mongod , then the method to get the correct link to it will use this method (which has an alias that is more gender-neutral getSiblingDB).

If you want to use a longer syntax, you can: db.getMongo().getDB(name) get the same as db.getSiblingDB(name) or db.getSisterDB(name) , but the first is longer for input.

All of the above works the same way in stand-alone mongod , as well as in replica sets (and cluster splinter).

+13
source share

I am going to add to the accepted answer because I did not find what I wanted as the first result.

getSiblingDB exists for scripts where helper use not available

getSiblingDB is newer between identical getSisterDB , so using sibling as getSisterDB no longer in the documentation

when used in the shell, getSiblingDB is used to get the database without changing the db variable

0
source share

All Articles