{"id":26718638,"url":"https://github.com/neverbot/mongoose-control","last_synced_at":"2026-02-26T01:53:12.664Z","repository":{"id":168180960,"uuid":"643830518","full_name":"neverbot/mongoose-control","owner":"neverbot","description":"Seed/fixtures framework and cli for node (v18+) and mongoose (v7+).","archived":false,"fork":false,"pushed_at":"2025-04-01T06:53:11.000Z","size":1153,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T09:04:11.579Z","etag":null,"topics":["fixtures","javascript","mongoose","node","seed"],"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/neverbot.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":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-22T08:45:54.000Z","updated_at":"2024-12-05T10:03:14.000Z","dependencies_parsed_at":"2024-12-31T09:42:13.667Z","dependency_job_id":"893b06a9-2320-44b3-a583-80b2e29b65ee","html_url":"https://github.com/neverbot/mongoose-control","commit_stats":{"total_commits":69,"total_committers":1,"mean_commits":69.0,"dds":0.0,"last_synced_commit":"902c5e03b755bbec0143c428fe278ee46fb872a7"},"previous_names":["neverbot/mongoose-control"],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverbot%2Fmongoose-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverbot%2Fmongoose-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverbot%2Fmongoose-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neverbot%2Fmongoose-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neverbot","download_url":"https://codeload.github.com/neverbot/mongoose-control/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248817244,"owners_count":21166210,"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":["fixtures","javascript","mongoose","node","seed"],"created_at":"2025-03-27T17:35:34.924Z","updated_at":"2026-02-26T01:53:07.623Z","avatar_url":"https://github.com/neverbot.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mongoose-control\n\n[![npm](https://img.shields.io/npm/dt/mongoose-control)](https://www.npmjs.com/package/mongoose-control)\n[![npm](https://img.shields.io/npm/dw/mongoose-control)](https://www.npmjs.com/package/mongoose-control)\n[![GitHub license](https://img.shields.io/github/license/neverbot/mongoose-control)](https://github.com/neverbot/mongoose-control/blob/master/LICENSE)\n[![npm](https://img.shields.io/npm/v/mongoose-control)](https://www.npmjs.com/package/mongoose-control)\n\nMigrations (pending) and seed/fixtures (already done) framework and cli for node (v18+) and mongoose (v7+).\n\nThis project is based in:\n\n- [`node-mongoose-fixtures`](https://github.com/kennethklee/node-mongoose-fixtures), by [Kenneth Lee](https://github.com/kennethklee).\n- [`node-mongodb-migrations`](https://github.com/neverbot/node-mongodb-migrations) by [Ivan Alonso (neverbot)](https://github.com/neverbot) forked from [`ikatun/node-migrate`](https://github.com/ikatun/node-migrate) by [ikatun](https://github.com/ikatun), in turn forked from [`tj/node-migrate`](https://github.com/tj/node-migrate) by [TJ Holowaychuk](https://github.com/tj).\n\nBoth projects use the MIT license. Please check its authors files for more information.\nBoth projects seem to be discontinued, so I decided to merge some of their features and create this new project.\n\n## Installation\n\n`npm i --save-dev mongoose-control` to use from your repository.\n\n`npm i -g mongoose-control` to use from the command line (see [CLI usage](#CLI)).\n\n## Usage\n\n```javascript\nimport { fixtures } from 'mongoose-control';\n\nawait fixtures({\n    \u003ccollection name\u003e: [\n      \u003crecord\u003e,\n      \u003crecord\u003e\n    ],\n    \u003ccollection name\u003e: [\n      \u003crecord\u003e,\n      \u003crecord\u003e\n    ]\n});\n```\n\n### Example\n\n```javascript\nimport mongoose from 'mongoose';\nimport { fixtures } from 'mongoose-control';\n\n// User\nconst userSchema = new mongoose.Schema({\n  username: String,\n  password: String,\n});\nmongoose.model('Users', userSchema);\n\n// Book\nconst bookSchema = new mongoose.Schema({\n  title: String,\n});\nmongoose.model('Books', bookSchema);\n\n// Create dataset immediately\n//   - data is an array of all the documents created\nlet data = await fixtures({\n  Users: [\n    { username: 'one', password: 'pass' },\n    { username: 'two', password: 'pass' },\n  ],\n  Books: [{ title: 'Enders Game' }, { title: 'Speaker of the Dead' }],\n});\n\n// Name a dataset for future use\nfixtures.save('Users', {\n  users: [\n    { username: 'one', password: 'pass' },\n    { username: 'two', password: 'pass' },\n  ],\n});\n\n// Use the named dataset\n//  - data is an array of all documents created\ndata = await fixtures('Users');\n```\n\n### Using files for fixtures and/or seeds\n\nCreate files for the data, i.e. `userFixtures.js`:\n\n```javascript\nimport { ObjectId } from 'mongodb';\n\n// you can have relations using the same ObjectIds in different collections\nconst userId1 = new ObjectId();\nconst bookId1 = new ObjectId();\n\nconst Users = [\n  {\n    _id: userId1,\n    name: 'Awesome User 1',\n    books: [bookId1],\n    ...\n  },\n  {\n    ...\n  },\n];\n\nconst Books = [\n  {\n    _id: bookId1,\n    title: 'Awesome Book 1',\n    ...\n  },\n  {\n    ...\n  },\n];\n\nexport default {\n  Users,\n  Books,\n};\n```\n\nNow you can use your fixtures in your tests or any other place:\n\n```javascript\nimport { fixtures } from 'mongoose-control';\nimport fixturesData from 'userFixtures.js';\n\nawait fixtures(fixturesData);\n```\n\nRemember Mongoose have to be initialized before using `fixtures()`, and the models\nwe are going to use have to be registered in Mongoose.\n\n### CLI\n\nYou can use some of the features of this package from the command line:\n\n```bash\n# install the package globally:\nnpm i -g mongoose-control\n\n# to see the available options:\nmongoose-control --help\n\n# use as seeder, with a seed file (you can use the test files):\nmongoose-control --url mongodb://localhost:27017/testing --models test/models/ seed test/example.data.js\n```\n\n## API\n\n### Create a dataset\n\n`async fixtures(dataset, \u003cmongoose instance\u003e);`\n\nImmediately creates the documents from the dataset through the mongoose connection. Returns a flat array with every inserted fixture.\n\n- `dataset` can be a hash or a name of a named fixture.\n- `mongoose instance` is optional and is a singular instance of mongoose.\n\n### Save a named fixture\n\n`fixtures.save(name, dataset);`\n\nSave a fixture to be used for later. Returns previous existent fixture with the same name, if it existed.\n\n- `name` is the name of your new named fixture.\n- `dataset` is the hash of the dataset you want to save.\n\n### Retrieve a named fixture's dataset\n\n`fixtures.get(name);`\n\nRetrieves a named fixture's dataset.\n\n- `name` is the name of the named fixture you wish to retrieve.\n\n### Clear named fixture\n\n`fixtures.clear(\u003cname\u003e);`\n\nClears named fixtures.\n\n- `name` is optional. It's the name of the named fixture. If omitted, all named fixtures will be cleared.\n\n### Reset database collection(s)\n\n`async fixtures.reset(\u003cmodel name\u003e, \u003cmongoose instance\u003e);`\n\nDeletes all documents within a collection. Returns the result of the delete operations.\n\n- `model name` is optional. It's the name of the collection. If omitted, all collections will be purged.\n- `mongoose instance` is optional and is a singular instance of mongoose.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneverbot%2Fmongoose-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneverbot%2Fmongoose-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneverbot%2Fmongoose-control/lists"}