1:mongodump -h IP --port 端口 -u 用戶名 -p 密碼 -d 數據庫 -o 文件存在路徑
如果沒有用戶誰,可以去掉-u和-p。
如果導出本機的數據庫,可以去掉-h。
如果是默認端口,可以去掉--port。
如果想導出所有數據庫,可以去掉-d。
導出指定數據庫:(此時只是導出ydkt下面的所有集合,但是集合時空的沒有數據)
root@y:mongodb# mongodump -h 127.0.0.1 -d ydkt -o /tmp/mongdb-tmp
2:mongorestore還原數據庫
mongorestore -h IP --port 端口 -u 用戶名 -p 密碼 -d 數據庫 --drop 文件存在路徑
還原指定的數據庫:
root@iZ283oqfkoeZ:mongo-tmp# mongorestore -d ydkt ydkt/
3:mongoexport導出表,或者表中部分字段
mongoexport -h IP --port 端口 -u 用戶名 -p 密碼 -d 數據庫 -c 表名 -f 字段 -q 條件導出 --csv -o 文件名
導出整張表:
root@y:mongodb# mongoexport -d ydkt -c bjs -o /tmp/mongdb-tmp/bjs.bat connected to: 127.0.0.1 exported 1 records
4:mongoimport導入集合(表),或者表中部分字段
root@iZ283oqfkoeZ:ydkt-c# mongoimport -d ydkt -c bjs --upsert bjs.bat 2015-06-20T11:44:58.051+0800 connected to: localhost 2015-06-20T11:44:58.054+0800 imported 1 document root@iZ283oqfkoeZ:ydkt-c#