1. 将user表导出 mongoexport
-o指明要导出的文件名, 本例中为”user.dat”
D:\Program Files\mongodb\Server\3.1\bin>mongoimport -d test -c user user.dat --现在导入数据
2015-05-05T15:45:13.016+0800 connected to: localhost
2015-05-05T15:45:13.021+0800 imported 5 documents
D:\Program Files\mongodb\Server\3.1\bin>mongo
2015-05-05T15:45:18.832+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.1.2
connecting to: test
Server has startup warnings:
2015-05-05T08:45:20.786+0800 I CONTROL [initandlisten]
2015-05-05T08:45:20.786+0800 I CONTROL [initandlisten] ** NOTE: This is a development version (3.1.2) of MongoDB.
2015-05-05T08:45:20.787+0800 I CONTROL [initandlisten] ** Not recommended for production.
2015-05-05T08:45:20.787+0800 I CONTROL [initandlisten]
> db.user.find() -- 现在可以看到原来的数据导入进去了
{ "_id" : ObjectId("55473cc3f2122f816c6dec1b"), "address" : { "city" : "dongguan", "province" : "shenzhen" }, "age" : 20, "loves" : [ "eat", "play", "drink" ], "name" : "tom2", "password" : "123456" }
{ "_id" : ObjectId("55473cb4f2122f816c6dec1a"), "address" : { "city" : "shiyan", "province" : "hubei" }, "age" : 24, "loves" : [ "eat", "play", "drink" ], "name" : "tom","password" : "123456" }
{ "_id" : ObjectId("55473ce1f2122f816c6dec1d"), "address" : { "city" : "shiyan", "province" : "guangdong" }, "age" : 20, "loves" : [ "eat", "play", "drink" ], "name" : "tom4", "password" : "123456" }
{ "_id" : ObjectId("55473cd3f2122f816c6dec1c"), "address" : { "city" : "changsha", "province" : "hunan" }, "age" : 20, "loves" : [ "eat", "play", "drin
db.user.find();
./ mongoexport -d test -c user -o user.dat
-d 指明使用的库, 本例中为” my_mongodb”
-c 指明要导出的表, 本例中为”user”-o指明要导出的文件名, 本例中为”user.dat”
从上面可以看到导出的方式使用的是 JSON的样式
2. 数据导入mongoimport
2.1 我们先将表user删除掉,以便演示效果
[root@localhost bin]# ./mongoimport -d test -c user user.dat> db.user.drop();true> show collections;fs.chunksfs.filespersionsystem.indexesusers> db.user.find() --这是候没数据> exitbye
D:\Program Files\mongodb\Server\3.1\bin>mongoimport -d test -c user user.dat --现在导入数据
2015-05-05T15:45:13.016+0800 connected to: localhost
2015-05-05T15:45:13.021+0800 imported 5 documents
D:\Program Files\mongodb\Server\3.1\bin>mongo
2015-05-05T15:45:18.832+0800 I CONTROL Hotfix KB2731284 or later update is not installed, will zero-out data files
MongoDB shell version: 3.1.2
connecting to: test
Server has startup warnings:
2015-05-05T08:45:20.786+0800 I CONTROL [initandlisten]
2015-05-05T08:45:20.786+0800 I CONTROL [initandlisten] ** NOTE: This is a development version (3.1.2) of MongoDB.
2015-05-05T08:45:20.787+0800 I CONTROL [initandlisten] ** Not recommended for production.
2015-05-05T08:45:20.787+0800 I CONTROL [initandlisten]
> db.user.find() -- 现在可以看到原来的数据导入进去了
{ "_id" : ObjectId("55473cc3f2122f816c6dec1b"), "address" : { "city" : "dongguan", "province" : "shenzhen" }, "age" : 20, "loves" : [ "eat", "play", "drink" ], "name" : "tom2", "password" : "123456" }
{ "_id" : ObjectId("55473cb4f2122f816c6dec1a"), "address" : { "city" : "shiyan", "province" : "hubei" }, "age" : 24, "loves" : [ "eat", "play", "drink" ], "name" : "tom","password" : "123456" }
{ "_id" : ObjectId("55473ce1f2122f816c6dec1d"), "address" : { "city" : "shiyan", "province" : "guangdong" }, "age" : 20, "loves" : [ "eat", "play", "drink" ], "name" : "tom4", "password" : "123456" }
{ "_id" : ObjectId("55473cd3f2122f816c6dec1c"), "address" : { "city" : "changsha", "province" : "hunan" }, "age" : 20, "loves" : [ "eat", "play", "drin