def upsert(self, *fields):
<EOL>if not self._id:<EOL><INDENT>return self.insert()<EOL><DEDENT>if self.count({'<STR_LIT>': self._id}) == <NUM_LIT:0>:<EOL><INDENT>self.insert()<EOL><DEDENT>else:<EOL><INDENT>self.update(*fields)<EOL><DEDENT>
Update or Insert this document depending on whether it exists or not.
The presense of an `_id` value in the document is used to determine if
the document exists.

NOTE: This method is not the same as specifying the `upsert` flag when
calling MongoDB. When called for a document with an `_id` value, this
method will call the database to see if a record with that Id exists,
if not it will call `insert`, if so it will call `update`. This
operation is therefore not atomic and much slower than the equivalent
MongoDB operation (due to the extra call).