- Reference >
mongoShell Methods >- Database Methods >
- db.getSiblingDB()
db.getSiblingDB()¶
On this page
Definition¶
-
db.getSiblingDB(<database>)¶ Parameter Type Description databasestring The name of a MongoDB database. Returns: A database object. Used to return another database without modifying the
dbvariable in the shell environment.
Example¶
You can use db.getSiblingDB() as an alternative to the use
<database> helper. This is particularly useful when writing scripts
using the mongo shell where the use helper is not
available. Consider the following sequence of operations:
This operation sets the db object to point to the database named
users, and then returns a count of the collection named
active. You can create multiple db objects, that refer to
different databases, as in the following sequence of operations:
This operation creates two db objects referring to different
databases (i.e. users and records) and then returns a
count and an
example document from
one collection in that database (i.e. active and requests
respectively.)