阅读背景:

JavaScript堆内存与真正巨大的mongo批量插入

来源:互联网 

Let take this sample

我们来看看这个样本

export let index = (req: Request, res: Response) => {


for (let i = 0; i < 10; i++) {
    let bulk = Faker.collection.initializeUnorderedBulkOp();
    for (let y = 0; y < 200000; y++) {
        bulk.insert({
            name: randomName(),
            nights: Math.random(),
            price: Math.random(),
            type1: Math.random(),
            type2: Math.random(),
            type3: Math.random(),
            type4: Math.random(),
            departure: mongoose.Types.ObjectId(randomAreaID()),
            destination: mongoose.Types.ObjectId(randomAreaID()),
            refundable: randomBool(),
            active: randomBool(),
            date_start: randomDate(),
            date_end: randomDate(),
        });
    }
    bulk.execute();
}


return res.json({data: true});

};
export let i



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: