title: Mongo Db Query: Update nested collection json property using switch/case or if/else condition
body: <p>I am using mongo db v4.4.
  I am trying to update property value using switch case conditional statement but getting error like..</p>
  <blockquote>
  <p>The dollar ($) prefixed field '$switch' in
  'template.0.children.2.isApplicable.$switch' is not valid for storage</p>
  </blockquote>
  <p><strong>Collection Json:</strong></p>
  <pre><code>{
    &quot;_id&quot;: &quot;61b6e8e9cee06e45b48af94b&quot;,
    &quot;countryCode&quot;: &quot;uk&quot;,
    &quot;template&quot;: [
      {
        &quot;children&quot;: [
          {
            &quot;propertyName&quot;: &quot;middle&quot;,
            &quot;isApplicable&quot;: true
          }
        ]
      }
    ]
  }
  </code></pre>
  <p><strong>Query:</strong></p>
  <pre><code>db.getCollection('mytestcollection').updateMany({
      &quot;template.children&quot;: {
          &quot;$elemMatch&quot;: {
              &quot;propertyName&quot;: &quot;middle&quot;
          }
      }
  }, {
      &quot;$set&quot;: {
          &quot;template.0.children.$[level1].isApplicable&quot;: {
              $switch: {
                  branches: [{
                          case: {
                              countryCode: {
                                  $in: ['uk']
                              }
                          },
                          then: false
                      }
  
                  ],
                 default: true
              }
          }
      }
  },
  {
      &quot;arrayFilters&quot;: [{
          &quot;level1.propertyName&quot;: &quot;middle&quot;
      }]
  });
  </code></pre>
  <p>How to solve above error and update property based on switch case/if else condition.</p>