{"id":16111787,"url":"https://github.com/cliffano/couchtato","last_synced_at":"2025-09-22T06:31:42.656Z","repository":{"id":1441124,"uuid":"1670832","full_name":"cliffano/couchtato","owner":"cliffano","description":"CouchDB database iterator tool","archived":false,"fork":false,"pushed_at":"2022-10-11T09:31:15.000Z","size":765,"stargazers_count":66,"open_issues_count":2,"forks_count":7,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-11T13:33:24.728Z","etag":null,"topics":["cli","couchdb","nodejs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cliffano.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-04-27T13:58:16.000Z","updated_at":"2024-08-25T00:25:23.000Z","dependencies_parsed_at":"2022-07-29T13:39:08.906Z","dependency_job_id":null,"html_url":"https://github.com/cliffano/couchtato","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fcouchtato","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fcouchtato/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fcouchtato/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cliffano%2Fcouchtato/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cliffano","download_url":"https://codeload.github.com/cliffano/couchtato/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233828160,"owners_count":18736581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","couchdb","nodejs"],"created_at":"2024-10-09T19:45:32.250Z","updated_at":"2025-09-22T06:31:37.380Z","avatar_url":"https://github.com/cliffano.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg align=\"right\" src=\"https://raw.github.com/cliffano/couchtato/master/avatar.jpg\" alt=\"Avatar\"/\u003e\n\n[![Build Status](https://img.shields.io/travis/cliffano/couchtato.svg)](http://travis-ci.org/cliffano/couchtato)\n[![Dependencies Status](https://img.shields.io/david/cliffano/couchtato.svg)](http://david-dm.org/cliffano/couchtato)\n[![Coverage Status](https://img.shields.io/coveralls/cliffano/couchtato.svg)](https://coveralls.io/r/cliffano/couchtato?branch=master)\n[![Published Version](https://img.shields.io/npm/v/couchtato.svg)](http://www.npmjs.com/package/couchtato)\n[![npm Badge](https://nodei.co/npm/couchtato.png)](http://npmjs.org/package/couchtato)\n\nCouchtato\n---------\n\nCouchtato is a CouchDB database iterator tool.\n\nThis is handy when you want to apply a set of JavaScript functions against all documents in a CouchDB database or view, or only some of them by specifying a start and/or an end key(s). On each JavaScript function, you can save a document, remove a document, log a message, or count the documents.\n\nPerformance and resource utilisation can be tuned by tweaking how many documents to retrieve per retrieval page, how many documents to update/remove per bulk update, and how many milliseconds interval between page retrievals.\n\nInstallation\n------------\n\n    npm install -g couchtato\n\nUsage\n-----\n\nCreate sample couchtato.js configuration file:\n\n    couchtato config\n\nIterate through all documents in a CouchDB database:\n\n    couchtato iterate -u http://user:pass@host:port/db\n\nIterate through all documents in a CouchDB view:\n\n    couchtato iterate -u http://user:pass@host:port/db/design/view\n\nUse custom configuration file:\n\n    couchtato iterate -u http://user:pass@host:port/db -c ../somecouchtato.js\n\nIterate through documents within a range of IDs:\n\n    couchtato iterate -u http://user:pass@host:port/db -s Astartkey -e Zendkey\n\nOnly iterate the first 5 pages where each page contains 1000 documents:\n\n    couchtato iterate -u http://user:pass@host:port/db -n 5 -p 1000\n\nSave/remove docs in bulk of 20000 documents at a time:\n\n    couchtato iterate -u http://user:pass@host:port/db -b 20000\n\nPause for 5 seconds between each page retrieval:\n\n    couchtato iterate -u http://user:pass@host:port/db -i 5000\n\nHide progress and summary info:\n\n    couchtato iterate -u http://user:pass@host:port/db -q\n\nConfiguration\n-------------\n\nSpecify the task functions in config file. Each function in exports.conf.tasks will be applied to each retrieved document one by one.\n\n    exports.conf = {\n        \"tasks\": {\n            \"log-all-docs\": function (util, doc) {\n                util.log(doc);\n            },\n            \"log-by-criteria\": function (util, doc) {\n                if (doc.title.match(/^The/)) {\n                    util.log(doc);\n                }\n            },\n            \"update-by-criteria\": function (util, doc) {\n                if (doc.status === 'new') {\n                    doc.owner = 'Bob McFred';\n                    util.save(doc);\n                }\n            },\n            \"delete-by-criteria\": function (util, doc) {\n                if (doc.status === 'spam') {\n                    util.remove(doc);\n                }\n            },\n            \"count-by-field\": function (util, doc) {\n                util.count(doc.status);\n            },\n            \"hash-doc\": function (util, doc) {\n                const hash = util.hash(doc);\n                util.log('hash:' + hash);\n            },\n            \"audit-object\": function (util, doc) {\n                util.audit(doc);\n            },\n            \"whatever\": function (util, doc) {\n                // you need to implement whatever function\n                whatever(doc);\n            }\n        }\n    }};\n\nDatabase driver is available via util.driver from the task function, it returns nano(url).use(db) :\n\n    exports.conf = {\n        \"tasks\": {\n            \"use-database-driver\": function (util, doc) {\n                util.driver.something();\n            }\n        }\n    }};\n\nNote that you can also require other Node.js modules in the config file if you need to.\n\nThe util variable\n-----------------\n\nThat 'util' in function (util, doc) is a utility variable, it provides you with the following convenient functions:\n\n    # save the document back to the database\n    util.save(doc)\n\n    # remove the document from the database\n    util.remove(doc)\n\n    # increment a counter associated with a particular key\n    # all counters will be displayed in the summary report\n    util.count('somekey')\n\n    # log a message to both the console and to couchtato.log file\n    # if you only want to display a message on the console,\n    # simply use good old console.log(message)\n    util.log(message)\n\n    # generate a SHA256 hash for a given document, object, or string\n    util.hash(doc)\n\n    # add an object to the audit array, which is returned in the\n    # callback and can be used for downstream processing\n    util.audit(doc)\n\nReport\n------\n\nA summary report will be displayed at the end of the run:\n\n    ------------------------\n    Retrieved 2601388 documents in 5203 pages\n    Processed 10356 saves and 302 removes\n    - New data count: 1012\n    - Moderated data count: 4578\n    - Flagged data count: 88\n\nSummary report can be excluded from the log output by using -q/--quiet option.\n\nFAQ\n---\n\nQ: Why am I getting 'exports' is undefined Microsoft JScript runtime error on Windows?\n\nA: Since Couchtato's default config file is called couchtato.js, Windows tried to execute couchtato.js instead of couchtato command, which then resulted in the above error. A workaround to this problem is to rename couchtato.js to config.js, and then use -c/--config-file flag, e.g. `couchtato --config-file config.js iterate --url http://user:pass@host:port/db`.\n\nQ: What is the purpose of `util.audit` and/or the audit array?\n\nA: The audit array is a convenient way to store data while iterating through documents. All objects added via `util.audit()` will be returned in the callback response upon completion. This is a powerful way to chain processing steps via messaging queues, lambda functions, or monitoring tools.\n\nColophon\n--------\n\n[Developer's Guide](https://cliffano.github.io/developers_guide.html#nodejs)\n\nBuild reports:\n\n* [Code complexity report](https://cliffano.github.io/couchtato/complexity/plato/index.html)\n* [Unit tests report](https://cliffano.github.io/couchtato/test/buster.out)\n* [Test coverage report](https://cliffano.github.io/couchtato/coverage/buster-istanbul/lcov-report/lib/index.html)\n* [Integration tests report](https://cliffano.github.io/couchtato/test-integration/cmdt.out)\n* [API Documentation](https://cliffano.github.io/couchtato/doc/dox-foundation/index.html)\n\nArticles:\n\n* [Couchtato – A CouchDB Document Utility Tool Written In Node.js](http://blog.shinetech.com/2011/06/30/couchtato-a-couchdb-document-utility-tool-written-in-nodejs/)\n\nRelated Projects:\n\n* [couchpenter](http://github.com/cliffano/couchpenter) - CouchDB database and document setup tool\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcliffano%2Fcouchtato","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcliffano%2Fcouchtato","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcliffano%2Fcouchtato/lists"}