{"id":15190617,"url":"https://github.com/steenhansen/mongoosetocsv","last_synced_at":"2025-10-02T06:31:58.409Z","repository":{"id":57302309,"uuid":"115560734","full_name":"steenhansen/mongooseToCsv","owner":"steenhansen","description":"Create .csv exports from mongoose models","archived":false,"fork":true,"pushed_at":"2018-01-02T19:33:01.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-18T01:19:32.239Z","etag":null,"topics":["csv","mongoose"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"nickpisacane/mongooseToCsv","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/steenhansen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-27T21:58:47.000Z","updated_at":"2019-02-26T07:06:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/steenhansen/mongooseToCsv","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/steenhansen%2FmongooseToCsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steenhansen%2FmongooseToCsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steenhansen%2FmongooseToCsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/steenhansen%2FmongooseToCsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/steenhansen","download_url":"https://codeload.github.com/steenhansen/mongooseToCsv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234951821,"owners_count":18912477,"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":["csv","mongoose"],"created_at":"2024-09-27T20:43:06.239Z","updated_at":"2025-10-02T06:31:58.101Z","avatar_url":"https://github.com/steenhansen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-to-csv-quotes\nMongooseToCsvQuotes is a mongoose plugin that creates a [`CsvBuilder`](https://github.com/nickpisacane/CsvBuilder) instance for your Schema. Updated [`mongoose-to-csv`](https://www.npmjs.com/package/mongoose-to-csv) package that escapes commas by default. Only if options.show_headers is true, are headers put in first row.\n\n## Usage\n```js\nconst mongooseToCsvQuotes = require('mongoose-to-csv-quotes') \n\nvar UserSchema = new mongoose.Schema({\n  fullname: {type: String},\n  email: {type: String},\n  age: {type: Number},\n  username: {type: String}\n});\n\nUserSchema.plugin(mongooseToCsvQuotes, {\n  headers: 'Firstname Lastname Username Email Age',\n  alias: {\n    'Username': 'username',\n    'Email': 'email',\n    'Age': 'age'\n  },\n  virtuals: {\n    'Firstname': function(doc) {\n      return doc.fullname.split(' ')[0];\n    },\n    'Lastname': function(doc) {\n      return doc.fullname.split(' ')[1];\n    }\n  }\n});\n\nvar User = mongoose.model('Users', UserSchema);\n\n// Query and stream\nUser.findAndStreamCsv({age: {$lt: 40}})\n  .pipe(fs.createWriteStream('users_under_40.csv'));\n\n// Create stream from query results\nUser.find({}).exec()\n  .then(function(docs) {\n    User.csvReadStream(docs)\n      .pipe(fs.createWriteStream('users.csv'));\n  });\n\n// Transform mongoose streams\nUser.find({})\n  .where('age').gt(20).lt(30)\n  .limit(10)\n  .sort('age')\n  .stream()\n  .pipe(User.csvTransformStream())\n  .pipe(fs.createWriteStream('users.csv'));\n```\n\n## Installation\n```sh\n$ npm install mongoose-to-csv-quotes\n```\n\n## Testing\nRunning tests requires a local mongodb server, and mocha. While most likely not a namespace issue, the test script will create a database `__mongoose_to_csv_test__`, and drop the database when finished. You have been warned.\n```sh\n$ npm test\n```\n\n## API\n\n#### Schema.plugin(mongooseToCsvQuotes, options)\nThe `options` argument is passed to the `CsvBuilder` instance, please refer to\nthe \u003ca href=\"https://github.com/Nindaff/CsvBuilder\"\u003eDocs\u003c/a\u003e for more in-depth details. The only aditional property that can be included is the `virutals` property.\nThe `virtuals` have nothing to do with mongoose virtuals.\n\n### Schema.csvReadStream([docs])\nCreates a csv formated read stream from query results.\n* docs Array\u003cModel\u003e\n\n### Schema.csvTransformStream()\nTransforms mongoose querystreams to csv formated streams.\n\n### Schema.findAndStreamCsv(query)\n* query Object Mongoose query\nThis is just a convenience method for:\n```js\nSchema.find(query).stream().pipe(Schema.csvTransformStream())\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteenhansen%2Fmongoosetocsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsteenhansen%2Fmongoosetocsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsteenhansen%2Fmongoosetocsv/lists"}