title: nodejs / mongoDb: update many fields in one request
body: <p>how can I update many orderStatus instead of only one?</p>
  <p><code>request.body.type</code> is by default string and contains only one type;</p>
  <p>and when <code>isCompleted</code> for the type go true I want even for previous enum index <code>isCompleted</code> go true</p>
  <p>is it possible or do I need to modify it in the front-end?</p>
  <p>here is the code</p>
  <pre class="lang-js prettyprint-override"><code>const orderSchema = new mongoose.Schema(
    {
      user: {
        type: mongoose.Schema.Types.ObjectId,
        ref: &quot;User&quot;,
        required: true,
      },
      orderStatus: [
        {
          type: {
            type: String,
            enum: [&quot;ordered&quot;, &quot;packed&quot;, &quot;shipped&quot;, &quot;delivered&quot;],
            default: &quot;ordered&quot;,
          },
          date: {
            type: Date,
          },
          isCompleted: {
            type: Boolean,
            default: false,
          },
        },
      ],
    }
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>exports.updateOrder = (req, res) =&gt; {
    Order.updateOne(
      { _id: req.body.orderId, &quot;orderStatus.type&quot;: req.body.type },
      {
        $set: {
          &quot;orderStatus.$&quot;: [
            { type: req.body.type, date: new Date(), isCompleted: true },
          ],
        },
      }
    ).exec((error, order) =&gt; {
  
  </code></pre>