halfmagic
12/13/2019 - 5:50 AM

MongoDB shell cheatsheet

mongoexport -c <collection name> -h <host> -u <username> -p <password> --type=csv --fields <field name 1>,<field name 2>,<...> --out <filename>.csv


mongoexport --db 'samsung-laptop' --collection retails -h 159.89.156.105:27017 -u 'samsungdoes' -p 'samsung7878*' --type=csv --fields index,retail,region,subRegion,name,address,uid --out modified_retail_list_191220.csv

mongo admin -u <username> -p <password> --authenticationDatabase <db name>
use <db name>
db.createUser({user: <user name>, pwd : <password>, roles:[<role name>]})
db.createCollection("<collection name>")