N
N
Nikolai Antonov2016-10-22 20:12:40
JavaScript
Nikolai Antonov, 2016-10-22 20:12:40

How to optimize insert in mongoDB with mongoose?

I use express+mongoose.
I am inserting 1 item in a cycle, and I have a lot of them - more than 1000. Somewhere at ~ 100, the insertion is interrupted. How can you create models and paste everything together?
My embed code:

var artistSchema = mongoose.Schema({
    name: {
        type: String,
        required: true
    }
})

let artistsTagA = [...] // массив с айтемами
artistsTagA.forEach(item => {
                    let Artist = mongoose.model(item, artistSchema, item)
                    let singleArtist = new Artist({
                        name: artistName,
                        link: `${SITE_URL}${raw[0]}`
                    })

                    singleArtist.save((err, singleArtist) => {
                        if (err) return console.error(err);
                        console.log(`Saved: ${singleArtist.name}`);
                    });

                })

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question