```
const cluster = require('cluster');
const numCPUs = require('os').cpus().length;

const dbConnect = require('./mongolib/dbConnect');
const SiretDB = require('./Model/siret');
const { saveManytoDb } = require('./DbUtils');
const fs = require('fs');
const JSONStream = require('JSONStream');

async function readsirets(workerId) {
  const stream = fs.createReadStream('./economicref-france-sirene-v3_public_2023.json', {
    encoding: 'utf8'
  });
  const parser = JSONStream.parse('*');

  stream.pipe(parser);

  parser.on('data', async data => {
    if (data.siret) {
      const siret = data.siret;
      const result = { siret };
      saveManytoDb(SiretDB, result);

      console.log(`Worker ${workerId} inserted data for siret ${siret}`);
    }
  });
}

if (cluster.isMaster) {
  console.log(`Master ${process.pid} is running`);

  // Fork workers
  for (let i = 0; i < numCPUs; i++) {
    cluster.fork();
  }

  cluster.on('exit', (worker, code, signal) => {
    console.log(`Worker ${worker.process.pid} died`);
  });

  for (const id in cluster.workers) {
    cluster.workers[id].on('message', message => {
      console.log(`Worker ${id} sent message: ${message}`);
    });
  }

} else {
  console.log(`Worker ${process.pid} started`);

  dbConnect().then(() => {
    readsirets(cluster.worker.id);
  });
}
```

i have this code to save data to mongodb, but this code is reading the stream on each forked process and inserting duplicated records..

can you fix the issue to read once's and insert in batch

 You should write your response with 1000 or more words.
user