通过Mongoose在MongoDB中存储巨大的JSON数据

时间:2022-12-02 02:34:10

Let's say I have an JavaScript Array companyBills and inside of it I have m objects stored in such manner; with m > 100.000 elements.

假设我有一个JavaScript Array公司账单,在其中我有以这种方式存储的m个对象; m> 100.000个元素。

{key_0:value_0, key_1:value_0_1, key_n:value_0_n},
{key_0:value_1, key_1:value_1_1, key_n:value_1_n},
{key_0:value_m, key_1:value_m_1, key_n:value_m_n}

Now I want to store this in MongoDB via Mongoose, in such a manner:

现在我想通过Mongoose将它存储在MongoDB中,方式如下:

CompanyBills.create (companyBills, function(err, jellybean, snickers) {
        if(!err) {          
          console.log('Success');
        } else {
          console.log('Error');
        }

However the array companyBills is too huge. Thus I want to store in chunks of 1/100 m. How to split the array companyBills Time-efficiently and store in MongoDB?

然而阵列公司的票据太大了。因此,我想以1/100米的大块存储。如何快速分割数组companyBills并存储在MongoDB中?

I am creating the array with https://github.com/SheetJS/js-xlsx, maybe there is an opportunity to hook-in early.

我正在使用https://github.com/SheetJS/js-xlsx创建数组,也许有机会尽早挂钩。

1 个解决方案

#1


2  

Have you tried the bulk insert method?

您是否尝试过批量插入方法?

CompanyBills.collection.insert([huge array], function (err, results) {
    Console.log(results)
})

http://docs.mongodb.org/manual/tutorial/insert-documents/

#1


2  

Have you tried the bulk insert method?

您是否尝试过批量插入方法?

CompanyBills.collection.insert([huge array], function (err, results) {
    Console.log(results)
})

http://docs.mongodb.org/manual/tutorial/insert-documents/