Updated on 2022-06-21 GMT+08:00

Creating and Managing Databases

For details about the rules of the write/update and delete commands, see Write/Update and Delete.

Procedure

  1. Create database info.

    use info

    Enter db. If the following information is displayed, the database is opened.

    info

  2. Insert a data record into the database.

    db.user.insert({"name": "joe"})

    Implicit collection is a collection that is created after data is inserted. To create a collection (table), you must insert a document (record) to make the collection creation take effect.

  3. View the database

    To view all databases, run the following command:

    show dbs

    The command output is as follows:

    admin   0.000GB
    config  0.000GB
    info    0.000GB
    local   0.083GB

  4. Delete the database. Run the following command to delete the info database:

    db.dropDatabase()

    The database is deleted if the following information is displayed:

    {"dropped" : "info", "ok" : 1}