Last active
July 20, 2022 05:30
-
-
Save apolloclark/8145c8e2bc7fe3d36d20498acd2ddd31 to your computer and use it in GitHub Desktop.
Revisions
-
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ mongo --hostname <hostname> \ --athenticationDatabase <database> ``` ##### disconnect ```shell exit quit() -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,7 @@ mongo --hostname <hostname> \ ##### disconect ```shell exit quit() ``` ##### clear screen -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,7 +24,7 @@ mongo --hostname <hostname> \ --athenticationDatabase <database> ``` ##### disconect ```shell exit ``` -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ## Setup ##### installation, Ubuntu https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ``` ##### debug logs ```shell # print the last 24 lines of the debug log sudo tail -24 /var/log/mongodb/mongod.log ```` <br/><br/><br/> -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ``` -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 10 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,6 @@ sudo apt-get install -y mongodb-org service mongod status ``` ##### 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/> -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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> \ -
apolloclark revised this gist
Apr 18, 2016 . No changes.There are no files selected for viewing
-
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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> ``` -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -75,6 +75,7 @@ db ##### create database ```shell use <new_database_name> ``` ##### delete database -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 49 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ``` -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 27 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ``` -
apolloclark revised this gist
Apr 18, 2016 . 1 changed file with 19 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ ## Setup ##### 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 ``` -
apolloclark created this gist
Apr 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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 ```