I’m a beginner with MongoDB and I’ve some questions:
-
When I’m connected to Mongo, and i execute
show dbsI see 2 databases:adminandlocal. What’s their role? Then if I execute an insert command likedb.foo.insert({"value":"mongo"}), thetestdatabase appears. Why? How can i specify a custom name for a database? -
With
show dbsI get the databases (somehow likeshow databasesin sql), how can I then list the collections inside a database (I would useshow tablesin sql)? -
When executing a command, the MongoDB tutorial always uses the
dbobject. Is it the main object (a sort of “connection” object) that has to used for executing commands or it’s something else?
Thanks!
adminandlocalcontain various settings local to the server, like users who are authenticated to connect. Under beginner usage, you shouldn’t need to worry about them at all. By default you connect to a database namedtest. To connect to a new database, justuse databasenamefrom the mongo command line, ormongo databasenamefrom your OS shell.use [database_name]and thenshow collectionsdbobject is your root handle to the currently-selected database on the mongo commmand line. The command line is really just a Javascript command line, and there are various mongodb-specific objects and functions exposed that let you do stuff. Tryhelp()for a full listing.