title: Mongoengine: Check if document is already in DB
body: <p>I am working on a kind of initialization routine for a MongoDB using mongoengine.</p>
  
  <p>The documents we deliver to the user are read from several JSON files and written into the database at the start of the application using the above mentioned init routine.</p>
  
  <p>Some of these documents have unique keys which would raise a <code>mongoengine.errors.NotUniqueError</code> error if a document with a duplicate key is passed to the DB. This is not a problem at all since I am able to catch those errors using <code>try-except</code>.</p>
  
  <p>However, some other documents are something like a bunch of values or parameters. So there is no unique key which a can check in order to prevent those from being inserted to the DB twice.
  I thought I could read all existing documents from the desired collection like this:</p>
  
  <pre><code>docs = MyCollection.objects()
  </code></pre>
  
  <p>and check whether the document to be inserted is already available in <code>docs</code> by using:</p>
  
  <pre><code>doc = MyCollection(parameter='foo')
  print(doc in docs)
  </code></pre>
  
  <p>Which prints <code>false</code> even if there is a <code>MyCollection(parameter='foo')</code> document in the the DB already.</p>
  
  <p>How can I achieve a duplicate detection without using unique keys?</p>