The Mongo shell

To access the Mongo shell, simply execute mongo from any terminal. The Mongo shell requires the mongod server to be currently running and available on the machine, as the first thing it does is connect to the server. Use the following command to access the Mongo shell:

    $ mongo
    MongoDB shell version: 2.4.5
    connecting to: test
    >

By default, when you first launch Mongo, you are connected to the local server and set to use the test database. To display a list of all databases on the server, use the following command:

    > show dbs

To switch databases to any of those listed in the output of show dbs, use the following command:

    > use chapter3
    switched to db chapter3

An interesting thing to note is that if you use use on a database that doesn't exist,
one will be created automatically. If you are using an existing database and want to view a list of collections in the database, execute the following command:

    > show collections

In this case of my chapter3 database, I had no existing collections since it was automatically generated as a new database for me. Collections in MongoDB are similar to the tables in a relational database.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.114.85