|
实用工具mongoexport 和mongoimport来进行数据的导入和导出
mongoexport导出:
有一张user 表,里面有2 条记录,我们要将它导出
> use my_testdb
switched to db my_testdb
> db.user.find();
{ "_id" :ObjectId("4f81a4a1779282ca68fd8a5a"), "uid" : 2,"username" : "Jerry", "age" : 100 }
{ "_id" :ObjectId("4f844d1847d25a9ce5f120c4"), "uid" : 1,"username" : "Tom", "age" : 25 }
>
导出方法:
[iyunv@localhost bin]# mongoexport-d my_testdb -c user -o user.dat
connected to: 127.0.0.1
exported 2 records
[iyunv@localhost bin]# catuser.dat
{ "_id" : {"$oid" : "4f81a4a1779282ca68fd8a5a" }, "uid" : 2,"username" : "Jerry", "age" : 100 }
{ "_id" : {"$oid" : "4f844d1847d25a9ce5f120c4" }, "uid" : 1,"username" : "Tom", "age" : 25 }
[iyunv@localhost bin]#
-d 指明使用的库
-c 指明要导出的表
-o 指明要导出的文件名
-csv 指要要导出为csv 格式
-f 指明需要导出哪些列
mongoimport导入:
先将表user 删除掉
> db.user.drop();
true
> show collections;
system.indexes
>
导入数据
[iyunv@localhost bin]# ./mongoimport -d my_testdb -c user user.dat
connected to: 127.0.0.1
imported 2 objects
[iyunv@localhost bin]#
|
|
|