{"id":34638974,"url":"https://github.com/haohanyang/mongodb-toolkit","last_synced_at":"2026-01-20T17:58:03.370Z","repository":{"id":319630524,"uuid":"1078723274","full_name":"haohanyang/mongodb-toolkit","owner":"haohanyang","description":"MongoDB utility libraries for data import/export and schema analysis","archived":false,"fork":false,"pushed_at":"2025-10-19T16:27:32.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-10-19T19:51:10.014Z","etag":null,"topics":["database","mongodb","node"],"latest_commit_sha":null,"homepage":"http://npmjs.com/package/mongodb-toolkit","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haohanyang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-18T09:30:51.000Z","updated_at":"2025-10-19T16:24:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"652e5187-9a1d-4e79-9e67-5d53cbb716d0","html_url":"https://github.com/haohanyang/mongodb-toolkit","commit_stats":null,"previous_names":["haohanyang/mongodb-toolkit"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/haohanyang/mongodb-toolkit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haohanyang%2Fmongodb-toolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haohanyang%2Fmongodb-toolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haohanyang%2Fmongodb-toolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haohanyang%2Fmongodb-toolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haohanyang","download_url":"https://codeload.github.com/haohanyang/mongodb-toolkit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haohanyang%2Fmongodb-toolkit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28005414,"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","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["database","mongodb","node"],"created_at":"2025-12-24T17:13:59.492Z","updated_at":"2025-12-24T17:14:01.918Z","avatar_url":"https://github.com/haohanyang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MongoDB Toolkit\n\nMongoDB Toolkit is a utility library that wraps utilities from [MongoDB Compass](https://github.com/mongodb-js/compass) for exporting data, importing data, analyzing schemas, and more.\n\n## Features\n\n- **Export Data**: Export MongoDB data to CSV or JSON files/streams.\n- **Import Data**: Import data from CSV or JSON files/streams into MongoDB.\n- **Schema Analysis**: Analyze MongoDB collections to generate schema definitions.\n\n## Installation\n\nTo install MongoDB Toolkit, use npm:\n\n```bash\nnpm install mongodb-toolkit\n```\n\nTo use the library with typescript, either set `\"skipLibCheck\": false` in your `tsconfig.json` or install type definitions:\n\n```\nnpm i @types/json-schema @types/reservoir -D\n```\n\n## Usage\n\nExamples use [MongoDB Sample Datasets](https://www.mongodb.com/docs/atlas/sample-data/)\n\n### Export Data to CSV\n\n```ts\nimport { exportCSV } from 'mongodb-toolkit';\n\nconst mongoClient = new MongoClient(process.env['MONGO_URI']!);\n\nconst cursor = mongoClient\n  .db('sample_airbnb')\n  .collection('listingsAndReviews')\n  .aggregate([{ $limit: 10 }, { $project: { listing_url: 1 } }]);\n\nexportCSV(cursor, fs.createWriteStream('output.csv'), {\n  delimiter: ';',\n  progressCallback: (idx, phase) =\u003e {\n    console.log(phase, idx);\n  },\n})\n  .then((result) =\u003e {\n    console.log('Export result', result);\n  })\n  .catch((err) =\u003e {\n    console.error(err);\n  })\n  .finally(() =\u003e {\n    mongoClient.close();\n    process.exit(0);\n  });\n```\n\n### Import CSV File\n\nCSV content (import.csv):\n\n```csv\nid,name\n1,John\n2,Jane\n3,Doe\n```\n\n```ts\nimport { importCSV } from 'mongodb-toolkit';\n\nconst mongoClient = new MongoClient(process.env['MONGO_URI']!);\n\nconst coll = mongoClient.db('mydb').collection('mycollection');\n\nimportCSV(coll, fs.createReadStream('./import.csv'), {\n  fields: { id: 'int', name: 'string' },\n  delimiter: ',',\n})\n  .then((result) =\u003e {\n    console.log('Import Result:', result);\n  })\n  .catch((err) =\u003e {\n    console.error(err);\n  })\n  .finally(() =\u003e {\n    mongoClient.close();\n    process.exit(0);\n  });\n```\n\n### Analyze Schema\n\n```ts\nimport { analyzeSchema } from 'mongodb-toolkit';\n\nconst mongoClient = new MongoClient(process.env['MONGO_URI']!);\n\n// Sample 100 docs\nconst cursor = mongoClient\n  .db('sample_mflix')\n  .collection('comments')\n  .aggregate([{ $limit: 100 }]);\n\nconst controller = new AbortController();\n\n// Abort the analysis after 1 second\nsetTimeout(() =\u003e {\n  controller.abort();\n}, 1000);\n\nanalyzeSchema(cursor, { abortSignal: controller.signal })\n  .then((schema) =\u003e schema.getMongoDBJsonSchema())\n  .then((jsonSchema) =\u003e {\n    if (!schema) {\n      // Aborted\n      throw new Error('Schema analysis aborted');\n    }\n    console.log(JSON.stringify(jsonSchema, null, 2));\n  })\n  .catch((err) =\u003e {\n    console.error(err);\n  })\n  .finally(() =\u003e {\n    mongoClient.close();\n    process.exit(0);\n  });\n```\n\nOutput\n\n```json\n{\n  \"bsonType\": \"object\",\n  \"required\": [\"_id\", \"date\", \"email\", \"movie_id\", \"name\", \"text\"],\n  \"properties\": {\n    \"_id\": {\n      \"bsonType\": \"objectId\"\n    },\n    \"date\": {\n      \"bsonType\": \"date\"\n    },\n    \"email\": {\n      \"bsonType\": \"string\"\n    },\n    \"movie_id\": {\n      \"bsonType\": \"objectId\"\n    },\n    \"name\": {\n      \"bsonType\": \"string\"\n    },\n    \"text\": {\n      \"bsonType\": \"string\"\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaohanyang%2Fmongodb-toolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhaohanyang%2Fmongodb-toolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhaohanyang%2Fmongodb-toolkit/lists"}