mysql数据导入到mongol中该如何导入?如果带认证的mongol数据库如何导入数据,robomongo客户端有提供导入或者导出数据么?
2条回答
- lailaizouzoua 2017-06-05 07:17关注
数据导出:先举个例子作为切入口:
需求:
将test数据库下的things集合中的所有文档导出到D:\mongo_data路径下
D:\mongo\bin>mongoexport -d test -c things -o d:\mongo_data\things.txt
cmd控制台返回导出的相关信息,如下所示
connected to: 127.0.0.1
exported 15 records
检验一下:
去D:\mongo_data找一下是否存在things.txt文件
打开D:\mongo_data\things.txt显示如下:
{ "_id" : 3 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55de" }, "x" : 6, "y" : 0 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55df" }, "x" : 6, "y" : 1 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e0" }, "x" : 6, "y" : 2 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e1" }, "x" : 6, "y" : 3 }
{
"_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e2" }, "add" : [ { "age" :
21, "name" : "jimvin" }, { "age" : 22, "name" : "jimvin" }, { "age" :
23, "name" : "jimvin" }, { "age" : 23, "name" : "jimvin" } ], "x" : 6,
"y" : 4 }
{ &qu缉伐光和叱古癸汰含咯ot;_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e3" }, "num" : 55, "x" : 6, "y" : 5 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e4" }, "age" : null, "num" : null, "......余下全文>>
;x" : 6, "y" : 6 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e5" }, "add" : [ "jimvin", "abc", "aaa" ], "num" : "abc", "x" : 6, "y" : 7 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e6" }, "age" : [ 7, 9 ], "name" : "jimvin", "num" : 20, "x" : 6, "y" : 8 }
{ "_id" : { "$oid" : "528ec3042e2ec9f2c3cd55e7" }, "age" : [ 7, 8, 9 ], "name" : "tom", "x" : 10, "y" : 9 }
{ "_id" : { "$oid" : "5296e6d68378a9afba69af46" }, "add" : { "age" : 20, "name" : "jimvin" }, "name" : "jim", "num" : 10 }
{ "_id" : { "$oid" : "529eab9552bf5eb74acdb35b" }, "name" : "person1", "addr" : { "city" : "a", "state" : "d" } }
{ "_id" : { "$oid" : "529eaba252bf5eb74acdb35c" }, "name" : "person1", "addr" : { "city" : "b", "state" : "c" } }
{ "_id" : { "$oid" : "529eabc352bf5eb74acdb35d" }, "name" : "person1", "addr" : { "city" : "a", "state" : "e" } }
从例子我们基本都能猜出 mongoexport的命令用法,下面我们再详细分析一下:- mongoexport --db
简写 mongoexport -d
指定要导出集合所在的数据库
eg:
D:\mongo\bin>mongoexport --db test
或 D:\mongo\bin>mongoexport -d test
或 D:\mongo\bin>mongoexport -db test
注意:
- 不能单独使用,至少还要指定集合才能导出成功。 否则显示如下错误: no collection specified!
- 假如指定的数据库名在MongoDB中是不存在的,也不会报错的。
-
mongoexport --collection
简写 mongoexport -c
指定要导出集合的名字
eg:
D:\mongo\bin>mongoexport --collection test
或 D:\mongo\bin>mongoexport -c test
或 D:\mongo\bin>mongoexport -collection test注意:
这里是可以正常运行起来的,这里MongoDB系统在没指定数据库来源时,默认从test数据
库找相应的集合的,然后把对应的文档输出到cmd控制台上,假如我们指定的集合名在test数据库是不存在的,也不会报错,只是返回“exported 0
records”这样的提示。 mongoexport --out
简写 mongoexport -o
指定导出数据文件的目录
eg:
D:\mongo\bin>mongoexport --out d:\mongo_data\things.txt
或 D:\mongo\bin>mongoexport -o d:\mongo_data\things.txt
或 D:\mongo\bin>mongoexport -out d:\mongo_data\things.txt
注意:不能单独使用,至少还要指定集合才能导出成功。
否则显示如下错误:
no collection specified!文件目录不能写成d:\mongo_data或 d:\mongo_data\或d:\之类的,否则报错如下:
coundn't open [d:\mongo_data]。
一定要带有文件名的(带有后缀的),一般为.txt,.csv,.json,.csv
csv和csv文件:都是常用的数据交互格式,均可以用excell打开。纯粹D:\mongo\bin>mongoexport --out d:\mongo_data\things.txt这样写,即使我们没指定集合,但系统依然会为我们创建things.txt这个文件的。
在RockMongo 导出test数据库mythings集合会是一个js文件:
如下所示:
/** mythings indexes **/
db.getCollection("mythings").ensureIndex({
"_id": NumberInt(1)
},[
]);
/** mythings indexes **/
db.getCollection("mythings").ensureIndex({
"location": 1,
"name": -1
},[解决 无用评论 打赏 举报 - mongoexport --db
简写 mongoexport -d
指定要导出集合所在的数据库
eg:
D:\mongo\bin>mongoexport --db test
或 D:\mongo\bin>mongoexport -d test
或 D:\mongo\bin>mongoexport -db test
注意:
悬赏问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮
- ¥15 ads仿真结果在圆图上是怎么读数的
- ¥20 Cotex M3的调试和程序执行方式是什么样的?
- ¥20 java项目连接sqlserver时报ssl相关错误
- ¥15 一道python难题3
- ¥15 牛顿斯科特系数表表示
- ¥15 arduino 步进电机