mongodump --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> --authenticationDatabase admin
--quiet
-- if system is running out of memory
--out
-- output directory -- defaults to dump/<db_name>
mongodump --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> --authenticationDatabase admin --quiet --out <FOLDER_NAME>
With Index Restore
mongorestore --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> foldername
Without Index Restore
mongorestore --noIndexRestore --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> foldername
Import Single Collection from CSV [1st Column will be treat as Col/Key Name]
mongoimport --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> --collection <COLLECTION_NAME> --type csv --headerline --file /path/to/myfile.csv
Import Single Collection from JSON
mongoimport --host <DB_HOST> --port <DB_PORT> -u <DB_USER> -p <DB_PASS> -d <DB_NAME> --collection <COLLECTION_NAME> --file input.json
mongo
use admin;
db.auth('<DB_USER>', '<DB_PASS>');
db.serverCmdLineOpts();
{
"argv" : [
"/usr/bin/mongod",
"--config",
"/etc/mongod.conf"
],
"parsed" : {
"config" : "/etc/mongod.conf",
"net" : {
"port" : 27017
},
"security" : {
"authorization" : "enabled"
},
"storage" : {
"dbPath" : "/var/lib/mongodb",
"journal" : {
"enabled" : true
}
},
"systemLog" : {
"destination" : "file",
"logAppend" : true,
"path" : "/var/log/mongodb/mongod.log"
}
},
"ok" : 1
}
Install New MongoDB Agent