'Overwrite or add the first document matched by the query.
:param write_concern: Extra keyword arguments are passed down which
will be used as options for the resultant
``getLastError`` command.  For example,
``save(..., write_concern={w: 2, fsync: True}, ...)`` will
wait until at least two servers have recorded the write and
will force an fsync on the primary server.
:param update: Django-style update keyword arguments
:returns the new or overwritten document
.. versionadded:: 0.10.2'

def upsert_one(self, write_concern=None, **update):

    atomic_update = self.update(multi=False, upsert=True, write_concern=write_concern, full_result=True, **update)
    if atomic_update['updatedExisting']:
        document = self.get()
    else:
        document = self._document.objects.with_id(atomic_update['upserted'])
    return document
