Last active
October 18, 2016 20:32
-
-
Save isc-rsingh/8a3ade8a33852b315726f1d194aa6e19 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Deletes documents returned from a view named 'badones' in a design document named 'logging' | |
# The view must emit doc._id as the key. Here's an example design document | |
# function (doc) { | |
# var badword = 'mistake'; | |
# if (doc.anotherprop && doc.anotherprop.substr(0, badword.length) === badword) { | |
# emit(doc._id, doc.anotherprop); | |
# } | |
# } | |
import requests | |
import os | |
from cloudant import cloudant | |
from cloudant.client import Cloudant | |
from cloudant.document import Document | |
CLOUDANT_USERNAME = os.getenv('CLOUDANT_USERNAME', 'inlineusername') | |
CLOUDANT_PW = os.getenv('CLOUDANT_PW', 'inlinepw') | |
CLOUDANT_DB = 'thedb' | |
LIMIT = 200 | |
totalrows = 1 | |
processedrows = 0 | |
if (CLOUDANT_PW): | |
u = 'https://'+CLOUDANT_USERNAME+':'+CLOUDANT_PW+'@'+CLOUDANT_USERNAME+'.cloudant.com/' | |
else: | |
u = 'https://'+CLOUDANT_USERNAME+'.cloudant.com/' | |
u += CLOUDANT_DB + '/_design/view/_view/vegas?reduce=false&limit='+str(LIMIT) | |
while (processedrows < totalrows): | |
r = requests.get(u) | |
rj = r.json() | |
if (totalrows==1): | |
totalrows = rj['total_rows'] | |
processedrows += LIMIT | |
with cloudant(CLOUDANT_USERNAME, CLOUDANT_PW, account=CLOUDANT_USERNAME) as client: | |
thedb = client[CLOUDANT_DB] | |
for doc in rj['rows']: | |
# print 'Deleting ' + doc['id'] + ': ' + doc['value'] + ' ...' | |
mydoc = thedb[doc['id']] | |
mydoc.delete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment