3

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.

0

3 Answers 3

4

From the console you can simply run show dbs

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

Sign up to request clarification or add additional context in comments.

5 Comments

its responding as-error: uncaughtException: Object #<Db> has no method 'adminCommand'
What version of mongo are you using? (check using mongo --version)
Also make sure you have not overwritten the db variable
I'm using version 2.4.5.
Are you using the mongo command directly for the db console? The exact command may be different if you are using a language driver. When I enter an undefined method into mongo it gives me TypeError: Property 'asdfjklj' of object test is not a function so I'm not sure how to reproduce your issue
2

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.

Comments

0

MongoDB is a serverside technology. JavaScript (unless you're using Node.js, in which case you should have tagged it) is a client-side technology. Might as well shout for someone in Japan to cook you dinner - too far. You would need to ask a server-side component to ask MongoDB for you and pass you the results.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.