mongodb 将数据库 file.json 导入 robo3T (robomongo)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23009146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 13:40:24  来源:igfitidea点击:

Import a data base file.json into robo3T (robomongo)

mongodbmean-stacknosql

提问by user2981029

I have a file named services.json containing a data base that I exported from a windows mongodb, and I want to import that file into robomongo (connected to mongodb installed by npm) on Ubuntu.

我有一个名为 services.json 的文件,其中包含我从 Windows mongodb 导出的数据库,我想将该文件导入 Ubuntu 上的 robomongo(连接到由 npm 安装的 mongodb)。

I'm a beginner and I don't know how to proceed, which terminal use (robomongo or Ubuntu)?

我是初学者,我不知道如何继续,使用哪个终端(robomongo 或 Ubuntu)?

回答by Varun Sukheja

to import data for a collection in Robomongo:

为 Robomongo 中的集合导入数据:

  1. Right click on collection.
  2. Select 'insert Document'.
    enter image description here
  3. Paste your json data
  4. Click validate.
  5. Click save.
  1. 右键单击集合。
  2. 选择“插入文档”。
    在此处输入图片说明
  3. 粘贴你的json数据
  4. 单击验证。
  5. 点击保存。

回答by user2981029

Ok, I found the answer. In shell Mac OS X or Unix type:

好的,我找到了答案。在外壳 Mac OS X 或 Unix 类型中:

$ mongoimport -d your Database Name -c your Collection Name --file /path/to/my/fileThatIwantToImport.json

回答by toddg

For anyone wishing to use mongoimport with a remote db (@andi-giga), here's what I did to make it work:

对于任何希望将 mongoimport 与远程数据库(@andi-giga)一起使用的人,这是我为使其工作所做的工作:

mongoimport -h  xxx.mlab.com --port 2700  -d db_name -c collection_name -u user_name -p password  --type json --file  /Path/to/file.json

Arguments should be self-explanatory.

参数应该是不言自明的。

-h hostname

-h hostname

More information at this link

更多信息请访问此链接

回答by Mohd Belal

RoboMongois just the UI for your mongodwhich is the primary daemon processfor the MongoDB system.

RoboMongo只是mongod的 UI,它是MongoDB 系统的主要守护进程

The only option to import from RoboMongo is

从 RoboMongo 导入的唯一选项是

Right Click on Collection -> Insert Document

Apart from this you can import using the mongoimportcommand from terminal.

除此之外,您可以从终端使用mongoimport命令导入。

  1. Open terminal and type mongo
  2. Now in mongo interactive shell
  3. Use the following command to import the json file as collection
  1. 打开终端并输入mongo
  2. 现在在 mongo 交互式 shell 中
  3. 使用以下命令将json文件作为集合导入

mongoimport -d database_name -c collection_name --file < path to the json file

mongoimport -d database_name -c collection_name --file < json 文件的路径

回答by K78

Tested :

测试:

mongoimport --jsonArray -d <DataBase Name> -c <Collection Name> --file /path/to/my/fileThatIwantToImport.json

It works very well!

它运作良好!

回答by Deck Pope

if this is not a bson, and only json, you can use mongoimport --jsonArray. refference Insert json file into mongodb

如果这不是 bson,而只有 json,则可以使用mongoimport --jsonArray. 参考将json文件插入mongodb

回答by mantzouric

Insert Document will insert all the JSON file data under a single document. Apparently the tool does not support JSON import.

插入文档将在单个文档下插入所有 JSON 文件数据。显然该工具不支持 JSON 导入。