windows環(huán)境下 , 利用mongoexport 與 mongoimport指令, 將數(shù)據(jù)從遠(yuǎn)程數(shù)據(jù)庫(kù)使用JSON文件形式導(dǎo)出, 以及將本地?cái)?shù)據(jù)使用JSON文件形式導(dǎo)入遠(yuǎn)程數(shù)據(jù)庫(kù).
1.進(jìn)入mongoDB安裝bin目錄, cmd打開(kāi)命令窗口,輸入指令
2.導(dǎo)出數(shù)據(jù)
mongoexport -h 需要導(dǎo)出數(shù)據(jù)的遠(yuǎn)程數(shù)據(jù)庫(kù)的IP與端口 -u 遠(yuǎn)程數(shù)據(jù)庫(kù)用戶名 -p 遠(yuǎn)程數(shù)據(jù)庫(kù)密碼 -d 指定數(shù)據(jù)庫(kù)名 -c 指定需要導(dǎo)入數(shù)據(jù)的集合 -o C:\xxx\xxx.json --type json
3.導(dǎo)入數(shù)據(jù)
mongoimport -h 需要導(dǎo)入數(shù)據(jù)的遠(yuǎn)程數(shù)據(jù)庫(kù)的IP與端口 -u 遠(yuǎn)程數(shù)據(jù)庫(kù)用戶名 -p 遠(yuǎn)程數(shù)據(jù)庫(kù)密碼 -d 指定數(shù)據(jù)庫(kù)名 -c 指定需要導(dǎo)入數(shù)據(jù)的集合 --file C:\xxx\xxx.json --type json
附
options:
--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
--port arg port. Can also use --host hostname:port
--ipv6 enable IPv6 support (disabled by default)
-u [ --username ] arg username
-p [ --password ] arg password
--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 if dbpath specified, each db is in a separate directory
-d [ --db ] arg database to use
-c [ --collection ] arg collection to use (some commands)
-f [ --fields ] arg comma separated list of field names e.g. -f name,age
--fieldFile arg file with fields names - 1 per line
-q [ --query ] arg query filter, as a JSON string
--csv export to csv instead of json
-o [ --out ] arg output file; if not specified, stdout is used
--jsonArray output to a json array rather than one object per
mongoexport -h xxx -u xxx -p xxx -d xxx -c xxx -o C:\xxx.csv --type csv -f "machineCode,sleepStage,template,attrs" -q "{\"template\":\"T10\",\"status\":true}"