Skip to content

Commit c276356

Browse files
authored
chore(mongo-import): Importa ocorrencias em pedaços de 50k
Deve deixar o processo mais rápido
1 parent 609e308 commit c276356

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/ocorrencia.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ const collection = client.database('dwc2json').collection('ocorrencias')
1212
console.debug('Cleaning collection')
1313
console.log(await collection.deleteMany({}))
1414

15+
const CHUNK_SIZE = 50000;
1516
for (const url of refUrls) {
1617
if (!url) continue
1718
console.debug(`Processing ${url}`)
1819
const json = await processaZip(url)
1920
const ocorrencias = Object.values(json)
2021
console.debug(`Inserting entries (${ocorrencias.length})`)
21-
for (let i = 0, n = ocorrencias.length; i < n; i += 5000) {
22-
console.log(`Inserting ${i} to ${Math.min(i + 5000, n)}`)
23-
await collection.insertMany(ocorrencias.slice(i, i + 5000), {
22+
for (let i = 0, n = ocorrencias.length; i < n; i += CHUNK_SIZE) {
23+
console.log(`Inserting ${i} to ${Math.min(i + CHUNK_SIZE, n)}`)
24+
await collection.insertMany(ocorrencias.slice(i, i + CHUNK_SIZE), {
2425
ordered: false
2526
})
2627
}

0 commit comments

Comments
 (0)