title: Trying to post array in my mongodb collection from POST API in node.js using mongoose and express
body: <p>This is my <strong>orders model</strong>.</p>
  
  <pre><code>const Order = mongoose.model('Order', new mongoose.Schema({
      saleprice: {type: Number},
      discount: {type: Number},
      products : [{
          type: productSchema
      }]
  }));
  </code></pre>
  
  <p>This is my <strong>products model</strong></p>
  
  <pre><code>const productSchema = new mongoose.Schema({
      name: {type: String, required: true},
      price: {type: Number, required: true},
      category: {type: String, required: true}
  });
  </code></pre>
  
  <p>Now I want to <strong>post multiple products in single order post API call</strong>; Currently using this approach but this is not working for arrays. How I can add multiple products just by sending multiple productIds in JSON format.</p>
  
  <pre><code>router.post('/', async(req, res) =&gt;{
  
      const product = await Product.findById(req.body.productId);
      if(!product) 
          return res.status(400).send('Invalid product.');
  
      const order =new Order({        
          saleprice: "790",
          discount: "100",
          products: [{
              _id: product._id,
              name: product.name,
              price: (product.price).toString(),
              category: product.category
          }]
      });
      await order.save();
      res.send(order);
  
  });
  </code></pre>