I have an array which stores huge data and I need to insert those data into MongoDB.
I am able to achieve this using below code. But it takes 1.5 min. I need to push within fraction of seconds. Is there any other way to push huge array data into MongoDB?
HeadDet is an array and has 3 million record.
session, err := mgo.Dial(“localhost”)
if err != nil {
panic(err)
}
defer session.Close()
// Optional. Switch the session to a monotonic behavior.
session.SetMode(mgo.Monotonic, true)
c := session.DB("Test").C("Indicators")
for i := 0; i < len(HeadDet); i++ {
err = c.Insert(HeadDet[i])
}
if err != nil {
log.Fatal(err)
}
I have referred this link