导出成功后我们看一下/data/t1.json文件的样式,是否是我们所希望的:
- [root@localhost data]# more t1.json
- { "_id" : { "$oid" : "4f927e2385b7a6814a0540a0" }, "age" : 2 }
- [root@localhost data]#
|
通过以上说明导出成功,但有一个问题,要是异构数据库的迁移怎么办呢?例如我们要将MongoDB的数据导入到MySQL该怎么办呢?MongoDB提供了一种csv的导出格式,就可以解决异构数据库迁移的问题了. 下面将foo库的t2表的age和name列导出, 具体如下:
- [root@localhost bin]# ./mongoexport -d foo -c t2
- connected to: 127.0.0.1
- exported 1 records
- [root@localhost bin]#
|
查看/data/t2.csv的导出结果:
- [root@localhost data]# more t2.csv
- age,name
- 1,"wwl"
- [root@localhost data]#
|
可以看出MongoDB为我们提供了一个强在的数据导出工具。
(2)mongoimport导入工具
MongoDB提供了mongoimport工具,可以把一个特定格式文件中的内容导入到某张collection中。工具帮助信息如下:
- [root@localhost bin]# ./mongoimport
- options:
-
- -v [
- verbosity e.g. -vvvvv)
- -h [
-
-
- -u [
- -p [
-
- path, instead of connecting to a mongod server -
- needs to lock the data directory, so cannot be used
- if a mongod is currently accessing the same path
-
- directory
- -d [
- -c [
- -f [
-
-
-
-
-
-
-
-
- upsert. You should make sure this is indexed
-
-
- limited to 4MB.
|