如何在MongoDB中插入许多数据

时间:2019-03-20 08:49:35

标签: node.js mongodb

当我向MongoDB中插入许多数据时,

主要代码如下:

arr = [obj, obj, obj, ...]的长度超过60000

//Girl is a Model in mondoDB

 jsonArr.forEach((v, i) => {
   const json = require(`../${f}/${v}`)
   json.userInfo.forEach((v, i) => {
     Girl({ ...v }).save(function (err, data) {
       if (err)  console.log(err)
     })
   })
 })

我使用insetMany它(就像大数据一样)也会导致错误:

Girl.insertMany(arr)

显示错误:

像这样:

MongoNetworkError:首次连接时无法连接到服务器[127.0.0.1:27017] [MongoNetworkError:0到127.0.0.1:27017的连接超时]

我应该如何将其放入MongoDB中,

0 个答案:

没有答案