title: Query an Array for an Element MongoDB Node.js
body: <p><a href="https://i.stack.imgur.com/JJtSC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JJtSC.png" alt="Database" /></a></p>
  <p>Goal: To retrieve all orders that contain the same products_id</p>
  <p>Example: I want to retrieve all orders with products_id: 001 ;
  it returns all contents of _id:006 and _id:007</p>
  <pre><code>async function retrieveProductOrderInDb(uri_, user_info) {
    try {
    const client = await  MongoClient.connect(uri_, {
      useUnifiedTopology: true, serverApi: ServerApiVersion.v1
    });
    const db = client.db(&quot;boreal_db&quot;);
    var orders_tb = db.collection(&quot;orders&quot;);
    //retrieve all orders associated to product_id 
    const response = await orders_tb.find({&quot;product_id&quot;: user_info.product_id},{
    }).toArray();
    client.close();
    return response;
  } catch(error) {
    client.close();
    console.log(error);
  }
  }
  
  //RETRIEVE ORDERS WITH MY PRODUCTS
  app.get(&quot;/retrieveProductOrder&quot;, (req, res) =&gt; {
    res.set({ &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot; });
    retrieveProductOrderInDb(uri, req.body).then((response) =&gt; {
      res.send(response);
    });
  });
  </code></pre>