Erase all documents in a Cloudant database
This is an example of how to delete all documents in a Cloudant database. This was primarily developed for the sake of easily resetting a demo I have given a number of times demonstrating capabilities of Node-RED with Cloudant, so why not have a flow that does this for me? Of course, be careful about using this on a production database unless you really want to delete all the documents.
The flow was exported from Node-RED running on IBM Bluemix. You'll have to fill in your own database name and service name pointing to your own Cloudant instance.
[{"id":"a142c6d7.88a83","type":"http in","name":"Reset Demo","url":"/api/resetDemo","method":"get","x":112.53328704833984,"y":751.5333433151245,"z":"36f263c6.53a2e4","wires":[["5a96f752.c66ff"]]},{"id":"5a96f752.c66ff","type":"cloudant in","service":"cloudantNoSQLDB","cloudant":"","name":"Get all docs","database":"testdb","search":"_all_","design":"","index":"","x":313.86663818359375,"y":751.9777526855469,"z":"36f263c6.53a2e4","wires":[["e2951da4.71e13"]]},{"id":"e511d10a.e37758","type":"http response","name":"Response","x":888.4443969726562,"y":812.5555419921875,"z":"36f263c6.53a2e4","wires":[]},{"id":"2fa22777.c85c98","type":"http request","name":"deleteDocs","method":"POST","ret":"obj","url":"https://test.com/testdb/_bulk_docs","x":755.2000122070312,"y":745.199951171875,"z":"36f263c6.53a2e4","wires":[["e511d10a.e37758"]]},{"id":"e2951da4.71e13","type":"function","name":"bulk delete function","func":"var count = msg.payload.length;\nvar list = [];\nfor (i=0;i<count;i++) {\nlist.push({\n _id: msg.payload[i]._id,\n _rev: msg.payload[i]._rev,\n _deleted: true\n });\n}\n\nif (i == 0) {\nmsg.payload = \"No documents were found. The database is empty!\";\nreturn [null, msg];\n}\n\nmsg.payload = {\n \"docs\": \n list\n }\nreturn msg;","outputs":"2","valid":true,"x":511.20001220703125,"y":752.199951171875,"z":"36f263c6.53a2e4","wires":[["2fa22777.c85c98","9b77e207.c43508"],["e511d10a.e37758","9b77e207.c43508"]]},{"id":"9b77e207.c43508","type":"debug","name":"","active":true,"console":"false","complete":"false","x":770.2000122070312,"y":854.2000732421875,"z":"36f263c6.53a2e4","wires":[]}]