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

To access ‘restaurants’ collection of PP database
db.getSiblingDB('PP').restaurants.find().pretty();
OR
db.getSiblingDB('PP').restaurants.findOne();

Output:-

Like this:
Like Loading...
About Prashanth Jayaram
DB Technologist, Author, Blogger, Service Delivery Manager at CTS, Automation Expert, Technet WIKI Ninja, MVB and Powershell Geek
My Profile:
https://social.technet.microsoft.com/profile/prashanth jayaram/
http://www.sqlshack.com/author/prashanth/
http://codingsight.com/author/prashanthjayaram/
https://www.red-gate.com/simple-talk/author/prashanthjayaram/
http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/
Connect Me:
Twitter @prashantjayaram
GMAIL powershellsql@gmail.com
The articles are published in:
http://www.ssas-info.com/analysis-services-articles/
http://db-pub.com/
http://www.sswug.org/sswugresearch/community/