You can use db.getSiblingDB() method to access another database without switching databases.
The current database is Test and accessing PP database temporarily from Test.
To List Collections of PP database and query collection named “restaurants”
db.getSiblingDB('PP').getCollectionNames()
The PP Database has three collections
- first
- restaurants
- second

Access restaurant collection of PP database
db.getSiblingDB('PP').restaurants.find().pretty(); ORdb.getSiblingDB('PP').restaurants.findOne();

Output:-
