将嵌套 JSON 文件转换并存储为 MongoDB 文档的最佳实践是什么?

发布于 2025-01-18 01:05:27 字数 207 浏览 2 评论 0原文

我有一个巨大(约1.8GB)的JSON文件,我的目标是在Express应用中使用的数据。加载JSON文件本身是不可行的,因为节点将导入到512MB。我是MongoDB的新手(通常是数据库),因此避免使用它们,但是,此问题似乎必须使用数据库来解决它。

我想知道是否有一种方法可以将我的JSON文件(包括5个级别嵌套的数据)转换为MongoDB文档,我可以使用Mongoose从服务器查询。

I have a huge (approx. 1.8gb) JSON file, the data of which I aim to use in an Express app. Loading the JSON file itself is infeasible as Node limits imports to 512mb. I am new to MongoDB (and databases in general) and thus have avoided using them so far, however, this issue appears as though it must be solved using a database.

I am wondering if there is a method by which I can convert my JSON file (which includes data nested up to 5 levels) into a MongoDB document that I can query from my server using Mongoose.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声静候 2025-01-25 01:05:27

我设法通过进一步搜索解决了这个问题。将最大对象转换为数组(创建一个在MongoDB中的16MB限制硬性编码下的2000个较小对象的数组)之后,我使用了 mongoimport 命令将JSON转换为文档。

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file JSON_FILE --jsonArray

I managed to resolve this issue through further searching. After converting the largest object into an array (creating an array of 2000 smaller objects that were under the 16mb limit hard coded in MongoDB), I used the mongoimport command to convert the JSON into documents.

mongoimport -d DATABASE_NAME -c COLLECTION_NAME --file JSON_FILE --jsonArray
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文