我正在尝试从使用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
发布评论