mongodb資料匯出匯入方法

2021-09-24 08:15:20 字數 968 閱讀 8980

1,匯出整個庫:

./mongodump -h 127.0.0.1:27017 -u test -p 123456 -d test -o /www/
2,匯出庫的單個集合:

./mongoexport -h 127.0.0.1:27017 -u test -p 123456 -d test -c test -o /www/test.json
-u 使用者名稱

-p 密碼

-d 庫名

-c 集合名稱

-o 匯出目錄

1,匯入整個庫

./mongorestore -h 127.0.0.1:27017 -d test --dir /www/tempdir/test/
2,單錶匯入

./mongoimport -h 127.0.0.1:27017 -d test --file test.json
-d 庫名

--dir 庫的資料目錄路徑

--file 匯入json檔案路徑

-c 追加的集合名稱(匯入單個集合追加資料使用,此處沒有使用)

2019-06-10t20:14:50.581+0800    failed: error connecting to db server: server returned error on sasl authentication step: authentication failed.

需要新增 --authenticationdatabase admin -u username -p pwd 引數,如:

./mongorestore --authenticationdatabase admin -u admin -p 123456 -h 127.0.0.1:27017 -d test --dir /www/tempdir/test/

MongoDB匯入匯出資料

匯出json格式 mongoexport d test c t1 o users lisa downloads t1.dat d 指明使用的庫 c 指明要匯出的集合 o 指明要匯出的檔名 檢視t1.dat發現裡面的資料是json格式的。mongoexport d test c t1 q o user...

mongodb 資料匯出匯入

mkdir p data eclassweb mongodump h 172.16.0.181 u eclassuser p eclassuser123 d eclassweb o data eclassweb opt mongodb 3.4.20 bin mongodump h 172.16.0....

MongoDB匯入匯出資料

1.匯出資料 h 資料庫位址,mongodb 伺服器所在的 ip 與 埠,如 localhost 27017 d 指明使用的資料庫例項,如 test c 指明要匯出的集合,如 mycol f 資料庫中想要匯出的字段 csv檔案匯出用的 o 指明要匯出的檔名,如 e abc xing.csv 注意是檔...