Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

311
Visualizações
Store many documents to mongoose fast

I need to insert 10K documents as fast as possible but it's taking a long time.

I am currently using Model.create([<huge array here>]) to do this.

Would it help to use multiple connections to the database? For example have 10 connections saving 1K each?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use model.insertMany(doc, options).

Some stuff to note below.

Connection Pool

10 connections is usually sufficient, but it greatly depends on your hardware. Opening up more connections may slow down your server.

In some cases, the number of connections between the applications and the database can overwhelm the ability of the server to handle requests.

Options

There are a couple of options for insertMany that can speed up insertion.

[options.lean «Boolean» = false] if true, skips hydrating and validating the documents. This option is useful if you need the extra performance, but Mongoose won't validate the documents before inserting.

[options.limit «Number» = null] this limits the number of documents being processed (validation/casting) by mongoose in parallel, this does NOT send the documents in batches to MongoDB. Use this option if you're processing a large number of documents and your app is running out of memory.

Write concern

Setting options on writeConcern in options can also affect performance.

If applications specify write concerns that include the j option, mongod will decrease the duration between journal writes, which can increase the overall write load.

over 4 years ago · Santiago Trujillo Relatório

0

Use db.collection.insertMany([])

insertMany will accept array of objects and this is use to perform bulk insertions.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda