从mongodb集合中导出有效的json

编程入门 行业动态 更新时间:2024-10-27 14:17:56
本文介绍了从mongodb集合中导出有效的json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试从使用node和instagram的api创建的mongodb集合中导出有效的json.我必须丢失一些东西,因为它看起来应该非常简单.我还阅读了其他帖子和mongo的文档,特别是有关mongoexport的文档. 我的最终目标是建立d3地图.我使用了文档中的基本mongoexport命令,它以以下格式返回了json文件:

I am trying to export valid json from a mongodb collection I created using node and instagram's api. I must be missing something as it seems like it should be super simple. I've read other posts and mongo's documentation, specifically about mongoexport. My end goal is to build a d3 map. I used the basic mongoexport command from the documentation and it returned a json file in the following format:

{'name':'dan'} {'name':'emma'}

有效的json是:

[{'name':'dan'}, {'name':'emma'}]

我知道有解决方法,即使是简单的解决方法,就像在崇高的文本中找到"$"一样,它会出现在每一行的末尾,然后可能会导致昏迷.最好是从技术上知道正确的方法.一篇文章建议使用JSON.parse,因此我使用fs.readFile尝试了此操作,但它返回错误:

I know there are workarounds to this, even one as simple as finding '$' in sublime text which would go to the end of every line, and then could just add a coma. It would just be great to know the proper way technically of doing this. One post suggested using JSON.parse, so I tried this using fs.readFile but it returns the error:

undefined:2 { "attribution" : null, "tags" : [], "location" : { "latitude" : 48.857141667, ^ SyntaxError: Unexpected token {.

我只需要将整个mongo集合导出到有效的json文件中即可(将成功通过 jsonlint/测试). 任何帮助将不胜感激.

I simply just need to export the entire mongo collection into a json file that's valid (would successfully pass jsonlint/ test). Any help would really be appreciated.

推荐答案

使用themongoexport util使用--jsonArray

using themongoexport util use --jsonArray

docs.mongodb/manual/参考/程序/mongoexport/#cmdoption--jsonArray

更多推荐

从mongodb集合中导出有效的json

本文发布于:2023-10-29 08:35:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mongodb   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!