title: How do I update if exist and insert if not using mongoengine (python)
body: <p>It is really absurd how mongoengine has such arcane documentation. I am trying to do a simple (update if exists query) based on a few columns/fields. What I mean by that is </p>
  
  <pre><code>if fieldA has valueA and 
     fieldB has valueB and 
     fieldC has valueC 
  then
  update fieldD with newValueD, 
         fieldE with newValueE
  </code></pre>
  
  <p>I could do it in the method mentioned below but I am pretty sure there is a really simple upsert syntax where if I mention the fields and values then it matches it across the collection, updates if they match and inserts if they don't</p>
  
  <pre><code>def __generateRemoteData(data):
      """
      Utils function to add remote data to Mongo
  
      """
      for datum in data:
          query = RemoteGraph.objects(
              Q(fieldA=datum.get('fieldA')) and
              Q(fieldB=datum.get('fieldB')) and
              Q(fieldC=datum.get('fieldC')) and
              Q(fieldD=datum.get('fieldD')) and
              Q(fieldE=datum.get('fieldE')) and
              Q(date=datum.get('date'))
          )
          if not query:
              RemoteGraph(
                  fieldA=datum.get('fieldA'),
                  fieldB=datum.get('fieldB'),
                  fieldC=datum.get('fieldC'),
                  fieldD=datum.get('fieldD'),
                  fieldE=datum.get('fieldE'),
                  date=datum.get('date'),
                  fieldF=datum.get('fieldF'),
                  fieldG=datum.get('fieldG'),
              ).save()
          else:
              query.update(
                  set__fieldF=datum.get('fieldF'),
                  set__fieldG=datum.get('fieldG'),
              )
  </code></pre>
  
  <p>Looking for a more pythonic way to do this.</p>
  
  <p>I have looked into <code>upsert</code>, <code>insert</code>, <code>modify</code>, <code>save</code>, <code>update</code>, <code>update_one</code></p>