{"id":21521077,"url":"https://github.com/weisjohn/mongoose-csv","last_synced_at":"2025-04-09T22:21:35.550Z","repository":{"id":57156679,"uuid":"43073383","full_name":"weisjohn/mongoose-csv","owner":"weisjohn","description":"generate CSVs from a mongoose schema","archived":false,"fork":false,"pushed_at":"2018-10-05T03:14:26.000Z","size":12,"stargazers_count":1,"open_issues_count":6,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T00:14:46.891Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/mongoose-csv","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/weisjohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2015-09-24T14:52:57.000Z","updated_at":"2024-06-22T02:57:32.000Z","dependencies_parsed_at":"2022-09-07T20:31:47.722Z","dependency_job_id":null,"html_url":"https://github.com/weisjohn/mongoose-csv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-csv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-csv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-csv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/weisjohn%2Fmongoose-csv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/weisjohn","download_url":"https://codeload.github.com/weisjohn/mongoose-csv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247934803,"owners_count":21020722,"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":[],"created_at":"2024-11-24T01:05:41.058Z","updated_at":"2025-04-09T22:21:35.524Z","avatar_url":"https://github.com/weisjohn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-csv\n\ngenerate CSVs from a mongoose schema\n\n### usage \n\n```javascript\nvar mongoose_csv = require('mongoose-csv');\nvar schema = new mongoose.Schema({ name: String });\nschema.plugin(mongoose_csv);\n```\n\nThis adds a `.csv()` function, which takes a [write-stream](https://nodejs.org/api/stream.html#stream_class_stream_writable), to the `mongoose.Query`, utilizing [mongoose QueryStream](http://mongoosejs.com/docs/api.html#querystream_QueryStream-pipe). This should be called after [query](http://mongoosejs.com/docs/api.html#query-js) calls, e.g. `.find()`, `.select()`, `.limit()`. This facilitates responding to an HTTP request, writing to a file, etc.\n\nFor example, a simple Express/Restify handler:\n\n```javascript\napp.get('/csv', function(req, res) {\n    res.writeHead(200, {\n        'Content-Type': 'text/csv',\n        'Content-Disposition': 'attachment; filename=sample.csv'\n    });\n    // pipe file using mongoose-csv\n    model.find().sort({ _id : 1 }).limit(100).csv(res);\n})\n```\n\nThis is faciliated by two lower-level methods, which are exposed for extensibility:\n\n - a static function to the schema `.csv_header()`, returning property names\n - an instance method on documents `.toCSV()`, returning values of a document\n\n\n### configuration\n\nBy default, `mongoose-csv` automatically includes any property with a type that is not `Array` or `Mixed` (this includes the nested properties of an `Object` type). Properties are returned in the order they are defined. Properties which are nested have a column name that is prefixed by their parent name and a period, e.g. `nested.foo` and `nested.bar` below.\n\nIf you want to prevent a property from the CSV output, annotate it with `{ csv : false }`. For example:\n\n```javascript\nvar schema = new mongoose.Schema({ \n    'name' : String,\n    'secret' : { type: String, csv: false },\n    'nested' : { \n        'foo' : String,\n        'bar' : Date\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fmongoose-csv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fweisjohn%2Fmongoose-csv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fweisjohn%2Fmongoose-csv/lists"}