MongoDB數(shù)據(jù)導(dǎo)入導(dǎo)出指令

windows環(huán)境下 , 利用mongoexport 與 mongoimport指令, 將數(shù)據(jù)從遠(yuǎn)程數(shù)據(jù)庫使用JSON文件形式導(dǎo)出, 以及將本地?cái)?shù)據(jù)使用JSON文件形式導(dǎo)入遠(yuǎn)程數(shù)據(jù)庫.

1.進(jìn)入mongoDB安裝bin目錄, cmd打開命令窗口,輸入指令

2.導(dǎo)出數(shù)據(jù)

mongoexport -h 需要導(dǎo)出數(shù)據(jù)的遠(yuǎn)程數(shù)據(jù)庫的IP與端口 -u 遠(yuǎn)程數(shù)據(jù)庫用戶名 -p 遠(yuǎn)程數(shù)據(jù)庫密碼 -d 指定數(shù)據(jù)庫名 -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ù)庫的IP與端口 -u 遠(yuǎn)程數(shù)據(jù)庫用戶名 -p 遠(yuǎn)程數(shù)據(jù)庫密碼 -d 指定數(shù)據(jù)庫名 -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}"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容