Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of all mongo databases in javascript while using any other database?

I'm trying to list all the databases while working inside some 'abc' database using javascript. my admin username is 'xyz' and password is 'abc'. But it is displaying an error- error: uncaughtException: Mongo is not defined. can anyone guide me for the same? thanx.

like image 892
Shobhit Mishra Avatar asked Jan 23 '26 11:01

Shobhit Mishra


2 Answers

From the console you can simply run show dbs

If you need the output in a Javascript object, try db.adminCommand('listDatabases')

like image 123
arcyqwerty Avatar answered Jan 25 '26 05:01

arcyqwerty


Actually the problem was with authentication of db. The mongo I'm using requires admin authentication before querying or trying any command to process data. I inserted code to authenticate db and got access to db.admin() function of mongodb.

By the way thanx to @arcyqwerty and @Amadan for your support.

like image 21
Shobhit Mishra Avatar answered Jan 25 '26 06:01

Shobhit Mishra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!