While playing with mognodb console help, I found a db.getSisterDB()
method.
And I am curious what is the purpose of this method. Looking through mongodb documentation and a quick google search did not yield satisfactory results.
By typing db.getSisterDb.help generates an error and typing db.getSisterDB
gives the following definition of this method:
function ( name ){
return this.getMongo().getDB( name );
}
which suggests that this is just a wrapper around getDB
. My suggestion that it is used in to access databases in a replica set, but I would like to listen to a person who can give me a more thorough explanation.
Using MongoDB can provide many benefits to a software development team. Its flexible schema makes it easy to evolve and store data in a way that is easy for programmers to work with. MongoDB is also built to scale up quickly and supports all the main features of modern databases such as transactions.
The db. getSiblingDB() method is used to provide access to the specified database. Syntax: db.getSiblingDB(<database>) Parameters: Name.
A single MongoDB server can have multiple databases and a single MongoDB database can have multiple collections. You can use MongoDB Shell or MongoDB Compass to create a new database. MongoDB provides the use <database-name command to connect with the database.
High performance (speed) Thanks to the document model used in MongoDB, information can be embedded inside a single document rather than relying on expensive join operations from traditional relational databases. This makes queries much faster, and returns all the necessary information in a single call to the database.
In the shell, db
is a reference to the current database. If you want to query against a different DB in the same mongod
instance, the way to get a proper reference to it would be to use this method (which has an alias, more gender neutral getSiblingDB).
If you wanted to use the longer syntax, you could: db.getMongo().getDB(name)
gets you the same thing as db.getSiblingDB(name)
or db.getSisterDB(name)
but the former is longer to type.
All of the above work the same way in standalone mongod
as well as replica sets (and sharded clusters).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With