Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anhnt/64380ecd69efd129b9d239fd54523c16 to your computer and use it in GitHub Desktop.

Select an option

Save anhnt/64380ecd69efd129b9d239fd54523c16 to your computer and use it in GitHub Desktop.

Revisions

  1. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 12 additions and 9 deletions.
    21 changes: 12 additions & 9 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,44 +1,47 @@
    NOTE - Remove **-h** option if you are doing operation on same machine
    NOTE -
    * Remove **-h** option if you are doing operation on same machine
    * Remove **-u** , **-p** option if your database don't have username and password


    ### Binary

    **Import database**
    ```
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    mongorestore -h IP:port -d DB_Name -u user_name -p password <input db directory>
    ```
    **Export database**
    ```
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    mongodump -h IP:port -d DB_Name -u user_name -p password -o <output directory>
    ```
    **Import collection**
    ```
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
    mongorestore -h IP:port -d DB_Name -u user_name -p password <input .bson file>
    ```
    **Export collection**
    ```
    mongodump -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output directory>
    mongodump -h IP:port -d DB_Name -c collection_name -u user_name -p password -o <output directory>
    ```


    ### JSON

    **Import collection**
    ```
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input file>
    mongoimport -h IP:port -d DB_Name -c collection_name -u user_name -p password --file <input file>
    ```
    **Export collection**
    ```
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output file>
    mongoexport -h IP:port -d DB_Name -c collection_name -u user_name -p password -o <output file>
    ```


    ### CSV

    **Import collection**
    ```
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    mongoimport -h IP:port -d DB_Name -c collection_name -u user_name -p password --file <input .csv file> --type csv --headerline
    ```
    **Export collection**
    ```
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>
    mongoexport -h IP:port -d DB_Name -c collection_name -u user_name -p password -o <output .csv file> --csv -f <comma-separated list of field names>
    ```
  2. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 1 addition and 1 deletion.
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    *NOTE - Remove **-h** option if you are doing operation on same machine*
    NOTE - Remove **-h** option if you are doing operation on same machine

    ### Binary

  3. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    *NOTE - Remove **-h** option if you are doing operation on same machine*

    ### Binary

    **Import database**
  4. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 21 additions and 9 deletions.
    30 changes: 21 additions & 9 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #### Binary
    ### Binary

    **Import database**
    ```
    @@ -8,23 +8,35 @@ mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    ```
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    ```
    #### Import collection
    **Import collection**
    ```
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
    #### Export collection
    ```
    **Export collection**
    ```
    mongodump -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output directory>
    ```


    *JSON*
    ### JSON

    #### Import collection
    **Import collection**
    ```
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input file>
    #### Export collection
    ```
    **Export collection**
    ```
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output file>
    ```


    *CSV*
    ### CSV

    #### Import collection
    **Import collection**
    ```
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    #### Export collection
    ```
    **Export collection**
    ```
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>
    ```
  5. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,13 @@
    #### Binary

    **Import database**
    ```
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    ```
    **Export database**
    ```
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    ```
    #### Import collection
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
    #### Export collection
  6. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #### Binary

    * Import database
    **Import database**
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    * Export database
    **Export database**
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    #### Import collection
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
  7. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    *Binary*
    #### Binary

    #### Import database
    * Import database
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    #### database
    * Export database
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    #### Import collection
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
  8. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,26 @@
    *Binary*

    Import database
    #### Import database
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    Export database
    #### database
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    Import collection
    #### Import collection
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
    Export collection
    #### Export collection
    mongodump -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output directory>


    *JSON*

    Import collection
    #### Import collection
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input file>
    Export collection
    #### Export collection
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output file>


    *CSV*

    Import collection
    #### Import collection
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    Export collection
    #### Export collection
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>
  9. @fahimbabarpatel fahimbabarpatel revised this gist Sep 30, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions Mongodb restore and dump commands via json, bson and csv.md
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,26 @@
    *Binary*

    Import database
    mongorestore -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> <input db directory>
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input db directory>
    Export database
    mongodump -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> -o <output directory>
    mongodump -h IP:port -d DB_Name -u <user> -p <password> -o <output directory>
    Import collection
    mongorestore -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> <input .bson file>
    mongorestore -h IP:port -d DB_Name -u <user> -p <password> <input .bson file>
    Export collection
    mongodump -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output directory>
    mongodump -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output directory>


    *JSON*

    Import collection
    mongoimport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> --file <input file>
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input file>
    Export collection
    mongoexport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output file>
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output file>


    *CSV*

    Import collection
    mongoimport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    mongoimport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    Export collection
    mongoexport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>
    mongoexport -h IP:port -d DB_Name -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>
  10. @fahimbabarpatel fahimbabarpatel renamed this gist Sep 30, 2015. 1 changed file with 0 additions and 0 deletions.
  11. @fahimbabarpatel fahimbabarpatel created this gist Sep 30, 2015.
    26 changes: 26 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    *Binary*

    Import database
    mongorestore -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> <input db directory>
    Export database
    mongodump -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> -o <output directory>
    Import collection
    mongorestore -h ds041871.mongolab.com:41871 -d azdms -u <user> -p <password> <input .bson file>
    Export collection
    mongodump -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output directory>


    *JSON*

    Import collection
    mongoimport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> --file <input file>
    Export collection
    mongoexport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output file>


    *CSV*

    Import collection
    mongoimport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> --file <input .csv file> --type csv --headerline
    Export collection
    mongoexport -h ds041871.mongolab.com:41871 -d azdms -c <collection> -u <user> -p <password> -o <output .csv file> --csv -f <comma-separated list of field names>