- Robo3T is recommended as a desktop client for managing the Mongo database.
CONNECT TO BITNAMI MEAN STACK
chmod 400 YourPEM.pem
ssh -i YourPEM.pem ubuntu@yourserveraddress.amazonaws.com
ssh -i YourPEM.pem bitnami@youripaddress
SETUP SSH TUNNEL TO CONNECT WITH ROBO 3T
ssh -N -L 27017:127.0.0.1:27017 -i "YourPEM.pem" ubuntu@yourserveraddress.amazonaws.com
ROBO 3T SETTINGS
Address: localhost:27017
Authentication: Database - admin, User Name - yourusername, Password - yourpassword
mongo --authenticationDatabase admin --host localhost --username yourusername --password yourpassword
db.createUser({user: "youradmin", pwd: "yourpassword", roles:[{role: "readWrite", db: "yourdb"}, {role: "dbAdmin", db: "yourdb"}]})
LOG INTO MONGODB COMMAND LINE
ssh -i YourPEM.pem bitnami@youripaddress
mongo -u yourusername -p yourpassword --authenticationDatabase yourdb
show dbs
use yourdb
db.getCollectionNames()
db.yourcollectionname.find()
db.yourcollectionname.remove({"userid":1, "date": 20190524})
exit
CSV IMPORT INTO MONGODB
IMPORTANT NOTE: You can rarely import external data as is, it will require
some manual "massaging" to make sure the schema and data types match,
otherwise the app may crash or act unpredictably (for example, wrong data type or missing data).
- Create a default CSV template
- After saving the file, you may need to open it in TextEdit to look at the raw CSV and search and replace a triple quote (
""") for a single quote (") to have it import correctly. A blank String field should only have double quotes (""). - Boolean values will be imported as strings, replace true with 1, false with 0 to import correctly
- Here is the command:
ssh -N -L 27017:127.0.0.1:27017 -i "YourPEM.pem" ubuntu@yourserveraddress.amazonaws.com
mongoimport -u yourusername -p yourpassword -d yourdatabase -c yourcollection --type csv --file yourfile.csv -v --headerline
MONGO DUMP/BACKUP
- You can backup the entire MongoDB instance using the following set of commands:
ssh -N -L 27017:127.0.0.1:27017 -i "YourPEM.pem" ubuntu@yourserveraddress.amazonaws.com
mongodump -u yourusername -p yourpassword -d yourdatabase --gzip --out `date +"%Y-%m-%d"` --forceTableScan
ADD A NEW FIELD TO ALL DOCUMENTS IN DATABASE
db.yourcollection.update({},{$set:{"video":""}},{upsert:false, multi:true})