db.getSisterDB() in mongoDB

db.getSisterDB()

This method is used to return another database without modifying the db variable in the shell environment.

Returns: A database object.

Syntax:

db.getSisterDB(name)


Example 1: When database name is passed as an argument.

MongoDB

db.getSisterDB("myUser")

Output:

myUser



Example 2: When database name is not passed as an argument.

MongoDB

db.getSisterDB()

Output:

Error: db initializer called with undefined argument :
Mongo.prototype.getDB@src/mongo/shell/mongo.js:61:12
getDatabase@src/mongo/shell/session.js:922:28
DB.prototype.getSiblingDB@src/mongo/shell/db.js:30:12
@(shell):1:1


No comments:

Post a Comment