导出数据
mongodump -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -o 文件存在路径
如果没有用户和密码,可以去掉-u和-p。
如果导出本机的数据库,可以去掉-h。
如果是默认端口,可以去掉--port。
如果想导出所有数据库,可以去掉-d
$>mongodump -h 192.168.164.202 --port 27017 -u dbs -p Abc12345 -d paperfareTable -o /
导出时的提示
connected to: 192.168.164.222:27017
2016-01-13T15:56:32.638+0800 DATABASE: paperfare to /paperfare
2016-01-13T15:56:32.660+0800 paperfare.system.indexes to /paperfare/system.indexes.bson
2016-01-13T15:56:32.662+0800 8 documents
2016-01-13T15:56:32.662+0800 paperfare.paperfareAutoIncTable to /paperfare/paperfareAutoIncTable.bson
2016-01-13T15:56:32.663+0800 25 documents
2016-01-13T15:56:32.663+0800 Metadata for paperfare.paperfareAutoIncTable to /paperfare/paperfareAutoIncTable.metadata.json
2016-01-13T15:56:32.663+0800 paperfare.paperfareTable to /paperfare/paperfareTable.bson
2016-01-13T15:56:32.672+0800 118 documents
2016-01-13T15:56:32.672+0800 Metadata for paperfare.paperfareTable to /paperfare/paperfareTable.metadata.json
2016-01-13T15:56:32.672+0800 paperfare.paperfareVersionTable to /paperfare/paperfareVersionTable.bson
2016-01-13T15:56:32.685+0800 1 documents
2016-01-13T15:56:32.685+0800 Metadata for paperfare.paperfareVersionTable to /paperfare/paperfareVersionTable.metadata.json
从远程192.168.164.202 机子中导到系统根目录下,跟目录下会自动生成paperfare文件价,数据的备份是bson,json结尾的数据格式,
导入:
mongoimport -h IP --port 端口 -u 用户名 -p 密码 -d 数据库 -c 表名 --upsert --drop 文件名
$>mongorestore -h 127.0.0.1 --port 27017 -p Abc12345 -d paperfare /paperfare
一下是打出的提示:
connected to: 127.0.0.1:27017
2016-01-13T16:04:53.131+0800 /paperfare/paperfareAutoIncTable.bson
2016-01-13T16:04:53.131+0800 going into namespace [paperfare.paperfareAutoIncTable]
25 objects found
2016-01-13T16:04:53.132+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "paperfare.paperfareAutoIncTable" }
2016-01-13T16:04:53.334+0800 /paperfare/paperfareTable.bson
2016-01-13T16:04:53.334+0800 going into namespace [paperfare.paperfareTable]
118 objects found
2016-01-13T16:04:53.336+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.341+0800 Creating index: { key: { paperfareDeparturePointList: 1 }, name: "paperfareDeparturePointList_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.343+0800 Creating index: { key: { paperfareDestinationPointList: 1 }, name: "paperfareDestinationPointList_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.345+0800 Creating index: { key: { paperfareDepartureDate: 1 }, name: "paperfareDepartureDate_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.347+0800 Creating index: { key: { id: 1 }, name: "id_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.348+0800 Creating index: { key: { seqNo: 1 }, name: "seqNo_", ns: "paperfare.paperfareTable" }
2016-01-13T16:04:53.350+0800 /paperfare/paperfareVersionTable.bson
2016-01-13T16:04:53.350+0800 going into namespace [paperfare.paperfareVersionTable]
1 objects found
2016-01-13T16:04:53.350+0800 Creating index: { key: { _id: 1 }, name: "_id_", ns: "paperfare.paperfareVersionTable" }
我是把数据导入到本地的数据库中,结束后数据库中可以直接找的该db。