title: Node.js/ - MongoDB async/await weird behaviour?
body: <p>Here, productIds has ID of all ordered items in an array like [&quot;1294382&quot;, &quot;2913892&quot;]</p>
  <p>So I'm trying to get all the items with those ID's from MongoDB's database. I'm mapping through each of them, and store them in orderedItems array. So that i can access price (or any property) of the item in database.</p>
  <pre><code>productRouter.post(&quot;/&quot;, async (req, res) =&gt; {
   
    const productIds = req.body.orderedItems.map((item) =&gt; item.id); 
  
    let orderedItems = [];
  
    productIds.map(async (productId) =&gt; {
      const d = await Product.findById(productId);
      orderedItems.push(d);
    });
  
    const unusedVariable = await Product.findById(&quot;61...da1&quot;); //If i delete that line (or only await), orderedItems returns empty array. 
  
    console.log(orderedItems);
    
  });
  </code></pre>
  <p>Now, expected output is:</p>
  <pre><code>[
    {
      _id: new ObjectId(&quot;614632cc8aa9513567dfbca4&quot;),
      name: 'ürün1',
      desc: 'ürün1 açıklama',
      price: 50,
      __v: 0
    },
    {
      _id: new ObjectId(&quot;614632cc8aa9513567dfbca2&quot;),
      name: 'kartal kupa',
      desc: 'kartal resimli kupa',
      price: 50,
      __v: 0
    }
  ]
  </code></pre>
  <p>And I get that output, but only if I have the unusedVariable line with await. If i remove that line, or remove &quot;await&quot; from there, the output i get is: [] . So an empty array instead of filled with objects.</p>
  <p>Why ? And how do i solve that (just leave unusuedVariable there?) ? How bad is this code ?</p>