title: Getting 300k data from mongodb
body: <p>I need to get 300k data with NodeJS from the database and pass it to the client(HTML side) for reporting and virtual scroll. I started with MySQL and it was taking around 14 seconds (2 tables joined). Since I'd like to speed up, I changed it to MongoDB but it takes around 31.2 seconds in one collection without any joining with the native MongoDB npm package.</p>
  <p>NodeJS MongoDB source code</p>
  <pre><code>  const { MongoClient } = require('mongodb');
    .
    .
    .
    const db = client.db(dbName);
    const collection = db.collection('test');
    const startTime = performance.now()
  
    const findResult = await collection.find({}).toArray();
    const endTime = performance.now();
    console.log(`Time elapsed: ${endTime - startTime} milliseconds`);  
    console.log('Found documents 1st element =&gt;', findResult[0]);
  </code></pre>
  <p>I'd assume MongoDB was going to take less time versus MySql but I guess there is something wrong with my code (I also tried fastify-mongodb, fast-json-stringify, streaming but none of them could not speed up ). What do you suggest? Because I researched lots of papers and most of the people gets +3m data around 10seconds and I know MongoDB is a good choice for big data even my data is not big enough :)</p>