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.
3 Answers
From the console you can simply run show dbs
If you need the output in a Javascript object, try db.adminCommand('listDatabases')
5 Comments
mongo --version)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 issueActually 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
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.