'Update or insert a document into Mongo'

@wrap_exceptions
def upsert(self, doc, namespace, timestamp):

    (database, coll) = self._db_and_collection(namespace)
    meta_collection_name = self._get_meta_collection(namespace)
    self.meta_database[meta_collection_name].replace_one({self.id_field: doc['_id'], 'ns': namespace}, {self.id_field: doc['_id'], '_ts': timestamp, 'ns': namespace}, upsert=True)
    self.mongo[database][coll].replace_one({'_id': doc['_id']}, doc, upsert=True)
