title: How to remove or add an element to an array in MongoDB
body: <p>I have a collection with documents that have an array field like so:</p>
  
  <pre><code>_id: 123
  my_array_field: [ 5, 7, 4]
  </code></pre>
  
  <p>Now I want to "toggle" the existence of an element in that array in a single operation. For example if I send the value 3, it should be added to the array as it is not in there yet. If I send the value 5, it should be removed. Is it possible to do that without querying the document beforehand?</p>
  
  <p>I am using the current version MongoDB (4.0.8) and the current NodeJS driver (3.2.3).</p>
  
  <p>Thank you!</p>