<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update(self, collection_name, instance):
 """ method finds Site Statistics record and update it DB representation """

        assert isinstance(instance, SiteStatistics)
        if instance.db_id:
            query = {'_id': ObjectId(instance.db_id)}
        else:
            query = {DOMAIN_NAME: instance.domain_name,
                     TIMEPERIOD: instance.timeperiod}
        self.ds.update(collection_name, query, instance)
        return instance.db_id