title: How to check if key exists in MongoDB
body: <p>I am trying to check if a key exists in a MongoDB collection. Basically, I need to map an array of strings to a specific key. If the key exists, I want to update the list by adding a new value, otherwise create a new key with an initial value (If a new key is added, it will only be added with 1 value initially).</p>
  <p>I have found some examples online, though I haven't been able to get it to work locally. Here is my code below (I am using the official Go MongoDB driver):</p>
  <pre><code>key:= &quot;some_key&quot;
  database := client.Database(&quot;dbName&quot;)
  keysCollection := database.Collection(&quot;keys&quot;)
  keysCollection.Find(nil, {key:{$exists:true}});
  </code></pre>
  <p>I'm running into 2 issues around this component <code>{key: {$exists:true}}</code></p>
  <ul>
  <li><code>invalid character U+0024 '$'</code>: when trying to check if the <code>key</code> exists, at <code>{$exists:true}</code>, though this seems to be what the MongoDB documentation supports to check if the key itself exists, without checking for an exact value mapped to it</li>
  <li><code>syntax error: unexpected {, expecting expression</code>: at the beginning of <code>{key: {$exists:true}}</code>, it looks like I cannot pass a struct?</li>
  </ul>
  <p>This is my first time working with MongoDB, and I have very little experience in GoLang, and am stuck on this seeming small issue.</p>
  <p>Am I going about this the right way? If so, how can I move past these issues?</p>