如何在 ubuntu 上的 mongodb 中导入 .json 文件?

我是 mongodb 的新手,我正在尝试导入 .json 文件。我在 sql developer 上创建了一个数据库,并将我的三个表导出到 3 个单独的 .json 文件中,如下所示,

{"results":[{"columns":[{"name":"CLUBID","type":"NUMBER"},{"name":"MANAGERID","type":"NUMBER"},{"name":"NAME","type":"VARCHAR2"},{"name":"CITY","type":"VARCHAR2"},{"name":"CREATION_DATE","type":"DATE"}],"items":
[
{"clubid":2001,"managerid":5376,"name":"FC KOPRITIS","city":"LAKONIA","creation_date":"03\/07\/99"}
,{"clubid":2002,"managerid":5377,"name":"FC NOE","city":"KITHERA","creation_date":"10\/11\/14"}
,{"clubid":2003,"managerid":5378,"name":"FC KRK","city":"MELOS","creation_date":"31\/01\/39"}
,{"clubid":2004,"managerid":5379,"name":"FC FOCUSRITE","city":"THERA","creation_date":"02\/02\/02"}
,{"clubid":2005,"managerid":5380,"name":"FC GHOST","city":"SERIFOS","creation_date":"05\/08\/64"}
,{"clubid":2006,"managerid":5431,"name":"FC ALITIS","city":"LIMNOS","creation_date":"22\/10\/45"}
,{"clubid":2007,"managerid":5432,"name":"FC VLOSPA","city":"MIKONOS","creation_date":"30\/08\/85"}
,{"clubid":2008,"managerid":5433,"name":"FC MADCLIP","city":"CAPITAL","creation_date":"01\/04\/01"}
,{"clubid":2009,"managerid":5436,"name":"FC SNIK","city":"ATHENS","creation_date":"18\/07\/98"}
,{"clubid":2010,"managerid":5435,"name":"FC YTM","city":"XANTHI","creation_date":"20\/04\/18"}
]}

我尝试使用 mongoimport --jsonArray --file club.json 但它没有用。我收到诸如“意外的 EOF”或“未指定集合”之类的错误

戴夫·圣某处

以下步骤导致成功导入:

获取要导入的所需记录(清理数据):

{"clubid":2001,"managerid":5376,"name":"FC KOPRITIS","city":"LAKONIA","creation_date":"03\/07\/99"}
{"clubid":2002,"managerid":5377,"name":"FC NOE","city":"KITHERA","creation_date":"10\/11\/14"}
{"clubid":2003,"managerid":5378,"name":"FC KRK","city":"MELOS","creation_date":"31\/01\/39"}
{"clubid":2004,"managerid":5379,"name":"FC FOCUSRITE","city":"THERA","creation_date":"02\/02\/02"}
{"clubid":2005,"managerid":5380,"name":"FC GHOST","city":"SERIFOS","creation_date":"05\/08\/64"}
{"clubid":2006,"managerid":5431,"name":"FC ALITIS","city":"LIMNOS","creation_date":"22\/10\/45"}
{"clubid":2007,"managerid":5432,"name":"FC VLOSPA","city":"MIKONOS","creation_date":"30\/08\/85"}
{"clubid":2008,"managerid":5433,"name":"FC MADCLIP","city":"CAPITAL","creation_date":"01\/04\/01"}
{"clubid":2009,"managerid":5436,"name":"FC SNIK","city":"ATHENS","creation_date":"18\/07\/98"}
{"clubid":2010,"managerid":5435,"name":"FC YTM","city":"XANTHI","creation_date":"20\/04\/18"}

验证您的文件位置、名称和路径。我的文件在我称为当前工作目录的子目录testData和名字json1.JSON

执行导入(如果数据库和集合不存在,将创建它们):

mongoimport --db tst2 --collection so2 --file testData/json1.JSON

结果:

2020-04-06T21:39:10.177-0400    connected to: mongodb://localhost/
2020-04-06T21:39:10.179-0400    10 document(s) imported successfully. 0 document(s) failed to import.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章