0 votes
in MongoDB by
Some beginner’s questions about MongoDB

1 Answer

0 votes
by
I’m a beginner with MongoDB and I’ve some questions:

When I’m connected to Mongo, and i executeshow dbs I see 2 databases: admin and local. What’s their role in MongoDB? Then if I execute an insert command likedb.foo.insert({“value”:”mongo”}), the test database appears. Why in MongoDB? How can i specify a custom name for a database in MongoDB?

Withshow dbs I get the databases (somehow like show databases in sql), how can I then list the collections inside a database (I would use show tables in sql) in MongoDB?

When executing a command, the MongoDB tutorial always uses thedb object. Is it the main object (a sort of “connection” object) that has to used for executing commands or it’s something else in MongoDB?

Thanks!

Adminand local contain 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 named test. To connect to a new database, just use databasename from the mongo command line, or mongo databasename from your OS shell.

Use [database_name]and then show collections

Thedb object is your root handle to the currently-selected database on the mongo command 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. Try help() for a full listing.

Related Page: MongoDB GUI - Top 7 MongoDB GUI Tools
...