
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to iterate over all MongoDB databases?
To iterate over all MongoDB databases, you need to switch your database to admin. Following is the query to switch to admin and get information about all the databases
> switchDatabaseAdmin = db.getSiblingDB("admin"); admin > allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases;
This will produce the following output
[ { "name" : "admin", "sizeOnDisk" : 495616, "empty" : false }, { "name" : "config", "sizeOnDisk" : 98304, "empty" : false }, { "name" : "local", "sizeOnDisk" : 73728, "empty" : false }, { "name" : "sample", "sizeOnDisk" : 1335296, "empty" : false }, { "name" : "sampleDemo", "sizeOnDisk" : 278528, "empty" : false }, { "name" : "studentSearch", "sizeOnDisk" : 262144, "empty" : false }, { "name" : "test", "sizeOnDisk" : 8724480, "empty" : false } ]
- Related Questions & Answers
- How to get all the collections from all the MongoDB databases?
- How to operate on all databases from the MongoDB shell?
- How to iterate over a Java list?
- How to iterate over a C# dictionary?
- How to iterate over a C# list?
- How to iterate over a C# tuple?
- Java Program to Iterate over enum
- How to iterate over a Hashmap in Kotlin?
- How to get the list of all the MongoDB databases using java?
- How to iterate over arrays and objects in jQuery?
- How to iterate over nodes of XML in JSP?
- Java Program to Iterate over a HashMap
- Java Program to Iterate over a Set
- Java Program to Iterate over an ArrayList
- How to find latest entries in array over all MongoDB documents?
Advertisements