joy460154849 2017-06-05 07:10 采纳率: 0%
浏览 20927

robomongo如何导入导出数据

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 注意:
      1. 不能单独使用,至少还要指定集合才能导出成功。 否则显示如下错误: no collection specified!
      2. 假如指定的数据库名在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
    },[

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器