title: How do I replace an entire array of subdocuments in MongoDB?
body: <p>Here is an example document from my collection:</p>
  
  <pre><code>Books
  [
     id: 1,
     links:
     [
       {text: "ABC", "url": "www.abc.com"},
       {text: "XYZ", "url": "www.xyz.com"}
     ]
  ]
  </code></pre>
  
  <p>I want to replace the links array in one update operation. Here is an example of how the above document should be modified:</p>
  
  <pre><code>Books
  [
     id: 1,
     links:
     [
       {text: "XYZ", "url": "www.xyz.com"},
       {text: "efg", "url": "www.efg.com"},   &lt;== NEW COPY OF THE ARRAY
       {text: "ijk", "url": "www.ijk.com"}
     ]
  ]
  </code></pre>
  
  <p>As you can see, the links array has been <strong>replaced</strong> (old data removed, and new data added).</p>
  
  <p>I am having very hard time with the <code>Update.Set()</code> because it says it <code>MyLinks&lt;&gt;</code> cannot be mapped to a <code>BsonValue</code></p>
  
  <p>I've tried many different ways of achieving this, and all of them fail, including <code>.PushAllWrapped&lt;WebLinkRoot&gt;("links", myDoc.WebLinks)</code>.
  Everything I've tried results in the new values being appended to the array, rather than the array being replaced.</p>
  
  <p>As it seems MongoDB doesn't provide a simple method to replace an array of subdocument OR  a method like <code>.ClearArray()</code>, what is the best way for me to ensure the array is cleared before adding new elements in a single query?</p>