def METHOD_NAME(self, couchUrl, couchDBName, metadata=None):
    """ Save this spec in CouchDB.  Returns URL """
    from WMCore.Database.CMSCouch import CouchServer, CouchInternalServerError
    metadata = metadata or {}
    server = CouchServer(couchUrl)
    database = server.connectDatabase(couchDBName)
    name = self.name()
    uri = '/%s/%s' % (couchDBName, name)
    specuri = uri + '/spec'
    if not database.documentExists(name):
        self.setSpecUrl(couchUrl + specuri)
        doc = database.put(uri, data=metadata, contentType='application/json')
        # doc = database.commitOne(self.name(), metadata)
        rev = doc['rev']
    else:
        # doc = database.get(uri+'?revs=true')
        doc = database.document(name)
        rev = doc['_rev']
    # specuriwrev = specuri + '?rev=%s' % rev
    # FIXME: once both central services and WMAgent are in Py3, we can remove protocol=0
    workloadString = pickle.dumps(self.data, protocol=0)
    # result = database.put(specuriwrev, workloadString, contentType='application/text')
    retval = database.addAttachment(name, rev, workloadString, 'spec')
    if retval.get('ok', False) is not True:
        msg = "Failed to save a spec attachment in CouchDB for %s" % name
        raise CouchInternalServerError(msg, data=None, result=retval)
    url = couchUrl + specuri
    return url