Skip to content

Instantly share code, notes, and snippets.

@apolloclark
Last active July 20, 2022 05:30
Show Gist options
  • Save apolloclark/8145c8e2bc7fe3d36d20498acd2ddd31 to your computer and use it in GitHub Desktop.
Save apolloclark/8145c8e2bc7fe3d36d20498acd2ddd31 to your computer and use it in GitHub Desktop.

Revisions

  1. apolloclark revised this gist Apr 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ mongo --hostname <hostname> \
    --athenticationDatabase <database>
    ```

    ##### disconect
    ##### disconnect
    ```shell
    exit
    quit()
  2. apolloclark revised this gist Apr 18, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -27,6 +27,7 @@ mongo --hostname <hostname> \
    ##### disconect
    ```shell
    exit
    quit()
    ```

    ##### clear screen
  3. apolloclark revised this gist Apr 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ mongo --hostname <hostname> \
    --athenticationDatabase <database>
    ```

    ##### quit
    ##### disconect
    ```shell
    exit
    ```
  4. apolloclark revised this gist Apr 18, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    ## Setup

    ##### Installation, Ubuntu
    ##### installation, Ubuntu

    https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

  5. apolloclark revised this gist Apr 18, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -60,8 +60,9 @@ https://docs.mongodb.org/manual/reference/configuration-options/
    sudo nano /etc/mongod.conf
    ```

    ##### system logs
    ##### debug logs
    ```shell
    # print the last 24 lines of the debug log
    sudo tail -24 /var/log/mongodb/mongod.log
    ````
    <br/><br/><br/>
  6. apolloclark revised this gist Apr 18, 2016. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,9 @@ shutdownServer()
    ```

    ##### configure, Ubuntu

    https://docs.mongodb.org/manual/reference/configuration-options/

    ```shell
    sudo nano /etc/mongod.conf
    ```
  7. apolloclark revised this gist Apr 18, 2016. 1 changed file with 10 additions and 5 deletions.
    15 changes: 10 additions & 5 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -15,11 +15,6 @@ sudo apt-get install -y mongodb-org
    service mongod status
    ```

    ##### configure, Ubuntu
    ```shell
    sudo nano /etc/mongod.conf
    ```

    ##### connect
    ```shell
    mongo --hostname <hostname> \
    @@ -56,6 +51,16 @@ getLastError()
    ```shell
    shutdownServer()
    ```

    ##### configure, Ubuntu
    ```shell
    sudo nano /etc/mongod.conf
    ```

    ##### system logs
    ```shell
    sudo tail -24 /var/log/mongodb/mongod.log
    ````
    <br/><br/><br/>


  8. apolloclark revised this gist Apr 18, 2016. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,11 @@ sudo apt-get install -y mongodb-org
    service mongod status
    ```

    ##### configure, Ubuntu
    ```shell
    sudo nano /etc/mongod.conf
    ```

    ##### connect
    ```shell
    mongo --hostname <hostname> \
  9. apolloclark revised this gist Apr 18, 2016. No changes.
  10. apolloclark revised this gist Apr 18, 2016. 1 changed file with 26 additions and 0 deletions.
    26 changes: 26 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -123,3 +123,29 @@ db.getCollectionNames()
    ##### clone database to remote server
    ```shell
    ```
    <br/><br/><br/>



    ## Scripting

    ##### import database
    ```shell
    mongoimport --db <database> \
    -c <collection> \
    --file <filename> \
    --type <type>
    ```

    ##### backup database
    ```shell
    mongodump --db <database> \
    -c <collection>
    ```

    ##### restore database, from backup
    ```shell
    mongorestore --db <database> \
    -c <collection> \
    <bson_file>
    ```
  11. apolloclark revised this gist Apr 18, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -75,6 +75,7 @@ db

    ##### create database
    ```shell
    use <new_database_name>
    ```

    ##### delete database
  12. apolloclark revised this gist Apr 18, 2016. 1 changed file with 49 additions and 1 deletion.
    50 changes: 49 additions & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -17,20 +17,44 @@ service mongod status

    ##### connect
    ```shell
    mongo --hostname <hostname> \
    --port <port> \
    -u <username> \
    -p <password> \
    --athenticationDatabase <database>
    ```

    ##### quit
    ```shell
    exit
    ```

    ##### clear screen
    ```shell
    <ctrl + l>
    ```

    ##### show version
    ```shell
    version()
    ```

    ##### show status
    ```shell
    hostInfo()
    stats()
    serverStatus()
    getLastError()
    ```

    ##### shutdown server
    ```shell
    shutdownServer()
    ```
    <br/><br/><br/>



    ## Databases

    ##### list databasess
    @@ -68,9 +92,33 @@ db.dropDatabase(); # Destroys the selected database



    ## Users

    ##### list users
    ```shell
    show users
    ```

    ##### create user
    ```shell
    db.AddUser({user: "<username>", pwd: "<password>", roles: ["readWrite"]});
    ```

    ##### delete user
    ```shell
    ```
    <br/><br/><br/>



    ## Collections

    ##### show collections
    ```shell
    show collections
    ```
    db.getCollectionNames()
    ```

    ##### clone database to remote server
    ```shell
    ```
  13. apolloclark revised this gist Apr 18, 2016. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -15,6 +15,21 @@ sudo apt-get install -y mongodb-org
    service mongod status
    ```

    ##### connect
    ```shell
    ```

    ##### quit
    ```shell
    exit
    ```

    ##### show version
    ```shell
    version()
    ```
    <br/><br/><br/>


    ## Databases

  14. apolloclark revised this gist Apr 18, 2016. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -29,6 +29,33 @@ show databases
    use <database_name>
    ```

    ##### show current database
    ```shell
    db
    ```

    ##### create database
    ```shell
    ```

    ##### delete database
    ```shell
    db.dropDatabase();
    ```

    ##### rename database
    ```shell
    db.copyDatabase('old_name', 'new_name'); # Copy the database to a new database
    use <old_name> # Switch to the database you wish to delete
    db.dropDatabase(); # Destroys the selected database
    ```
    <br/><br/><br/>



    ## Collections

    ##### show collections
    ```shell
    show collections
    ```
  15. apolloclark revised this gist Apr 18, 2016. 1 changed file with 19 additions and 1 deletion.
    20 changes: 19 additions & 1 deletion mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@

    ## Setup

    ### Installation, Ubuntu
    ##### Installation, Ubuntu

    https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

    @@ -13,4 +13,22 @@ echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    service mongod status
    ```


    ## Databases

    ##### list databasess
    ```shell
    show dbs
    show databases
    ```

    ##### connect to database
    ```shell
    use <database_name>
    ```

    ##### create database
    ```shell
    ```
  16. apolloclark created this gist Apr 18, 2016.
    16 changes: 16 additions & 0 deletions mongodb cheatsheet.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # MongoDB Cheatsheet

    ## Setup

    ### Installation, Ubuntu

    https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

    ```shell
    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
    echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | \
    sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
    sudo apt-get update
    sudo apt-get install -y mongodb-org
    service mongod status
    ```