def upsert_document(self, document, database_name=None, collection_name=None, document_id=None):
<EOL>if document_id is None:<EOL><INDENT>document_id = str(uuid.uuid4())<EOL><DEDENT>if document is None:<EOL><INDENT>raise AirflowBadRequest("<STR_LIT>")<EOL><DEDENT>if '<STR_LIT:id>' in document:<EOL><INDENT>if document['<STR_LIT:id>'] is None:<EOL><INDENT>document['<STR_LIT:id>'] = document_id<EOL><DEDENT><DEDENT>else:<EOL><INDENT>document['<STR_LIT:id>'] = document_id<EOL><DEDENT>created_document = self.get_conn().CreateItem(<EOL>get_collection_link(<EOL>self.__get_database_name(database_name),<EOL>self.__get_collection_name(collection_name)),<EOL>document)<EOL>return created_document<EOL>
Inserts a new document (or updates an existing one) into an existing
collection in the CosmosDB database.