##MongoDB导出数据
bin/mongoexport --host 192.168.1.15:40000 -d nsmongo -c userNoBaseInfo -f userId --csv -o ./userNoBaseInfo.csv
##MongoDB 备份数据库
bin/mongodump -h 192.168.1.107:40000 -d nsmongo -c postStore -q {"createdAt" : {"$gte": new Date(2013,4,1,0,0,0), "$lt" : new Date(2013, 5, 1, 0, 0, 0)}} -o /data/back/
bin/mongodump --help
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity e.g. -vvvvv)
--version print the program's version and exit
-h [ --host ] arg mongo host to connect to ( <set
name>/s1,s2 for sets)
--port arg server port. Can also use --host
hostname:port
--ipv6 enable IPv6 support (disabled by
default)
-u [ --username ] arg username
-p [ --password ] arg password
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR)
authentication mechanism
--dbpath arg directly access mongod database files
in the given path, instead of
connecting to a mongod server - needs
to lock the data directory, so cannot
be used if a mongod is currently
accessing the same path
--directoryperdb each db is in a separate directly
(relevant only if dbpath specified)
--journal enable journaling (relevant only if
dbpath specified)
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-o [ --out ] arg (=dump) output directory or "-" for stdout
-q [ --query ] arg json query
--oplog Use oplog for point-in-time
snapshotting
--repair try to recover a crashed database
--forceTableScan force a table scan (do not use
$snapshot)
mongodump -h dbhost -d dbname -o dbdirectory
##MongoDB 恢复数据库
mongorestore -h 192.168.1.107 -p 40000 --d nsmongo -c postStore --directoryperdb /data/back/nsmongo
bin/mongorestore --help
-h [ --host ] arg mongo host to connect to ( <set name>/s1,s2 for sets)
--port arg server port. Can also use --host hostname:port
--ipv6 enable IPv6 support (disabled by default)
-u [ --username ] arg username
-p [ --password ] arg password
--authenticationDatabase arg user source (defaults to dbname)
--authenticationMechanism arg (=MONGODB-CR) authentication mechanism
--dbpath arg directly access mongod database files
in the given path, instead of
connecting to a mongod server - needs
to lock the data directory, so cannot
be used if a mongod is currently
accessing the same path
--directoryperdb each db is in a separate directly (relevant only if dbpath specified)
--journal enable journaling (relevant only if dbpath specified)
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
--objcheck validate object before inserting (default)
--noobjcheck don't validate object before inserting
--filter arg filter to apply before inserting
--drop
mongorestore -h dbhost -d dbname --directoryperdb dbdirectory