0

when I insert many Data to MongoDB,

the main code like this:

like an

arr = [obj, obj, obj, ...] it's length like more 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)
     })
   })
 })

I use insetMany it (what like big data ) also cause the error :

Girl.insertMany(arr)

it show an error:

like this:

MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connection 0 to 127.0.0.1:27017 timed out]

how should I put it into MongoDB,

猪八戒
  • 11
  • 3
  • Possible duplicate of [MongoNetworkError: failed to connect to server \[localhost:27017\] on first connect \[MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017\]](https://stackoverflow.com/questions/50173080/mongonetworkerror-failed-to-connect-to-server-localhost27017-on-first-connec) – lifeisfoo Mar 20 '19 at 08:52
  • https://www.guru99.com/add-mongodb-array-using-insert.html please refer this, this will solve your problem – Narendra Chouhan Mar 20 '19 at 09:11

0 Answers0