title: Is there any way that backend does not have to request database for data multiple times in Node JS?
body: <p>For eg.</p>
  
  <p>I have 20000 meals in database</p>
  
  <p>The first request comes from frontend: I have to display 10 meals only,</p>
  
  <p>So I send a request to the backend to fetch 1000 meals from the database,
     and then from those 1000 meals I display the first 10 meals only(meal1, meal2,..., meal10).</p>
  
  <p>Then the page is scrolled until it needs to display more meals</p>
  
  <p>The second request comes:</p>
  
  <p>Now when the frontend asks 11-20 meals from backend,
      the backend should not go to the database for this request,
      it should display these data from the 1000 meals that the backend fetched from database in 1st request</p>
  
  <p>Just curious to know if this is possible...</p>
  
  <p>Thanks for your time...</p>
  
  <pre><code>Meal.aggregate([{
          $skip: (req.query.page - 1) * 10,
          },{$lookup: {
              from: 'restaurants',
              localField: 'restaurantID',
              foreignField: '_id',
              as: 'restaurant'
          }
          }, {
              $replaceRoot: {newRoot: {$mergeObjects: [{$arrayElemAt: ["$restaurant", 0]}, "$$ROOT"]}}
          }, {
              $addFields: {
                  returnObject: {
                      $or: [
                          {$regexMatch: {input: '$mealName', regex: search}}, 
                          {$regexMatch: {input: '$name', regex: search}}
                      ]
                  }
              }
          }, {
              $match: {'returnObject': {$ne: false}, 'nutrient': {$ne: {}}, mealPrice: {$lt: req.query.upperPrice, $gt: req.query.lowerPrice}}
          }, {
              $project: { mealName: 1, name: 1, nutrient: 1, mealPrice: 1}
          }, {
              $limit: 5000
          }]);
  </code></pre>
  
  <p>This is the query that I am using to get data from the database,</p>
  
  <p>After I received data, I need to perform some calculations which are going to change from user to user.</p>
  
  <p>Then I will apply pagination on the calculated data.</p>
  
  <p>So the problem is when the second request comes, my current system does all the calculations and then it displays the next 10 data.</p>
  
  <p>So I need to somehow save those calculations that I did when the first request arrived.</p>