{"id":18552441,"url":"https://github.com/andrejewski/fakegoose","last_synced_at":"2025-04-09T22:31:53.592Z","repository":{"id":57232525,"uuid":"54688509","full_name":"andrejewski/fakegoose","owner":"andrejewski","description":"Faker + Mongoose","archived":false,"fork":false,"pushed_at":"2019-12-19T20:34:05.000Z","size":11,"stargazers_count":32,"open_issues_count":8,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T00:02:38.062Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrejewski.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":"2016-03-25T02:27:17.000Z","updated_at":"2023-12-31T01:41:20.000Z","dependencies_parsed_at":"2022-08-31T14:10:57.591Z","dependency_job_id":null,"html_url":"https://github.com/andrejewski/fakegoose","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ffakegoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ffakegoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ffakegoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrejewski%2Ffakegoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrejewski","download_url":"https://codeload.github.com/andrejewski/fakegoose/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248123739,"owners_count":21051521,"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-06T21:14:13.492Z","updated_at":"2025-04-09T22:31:53.162Z","avatar_url":"https://github.com/andrejewski.png","language":"JavaScript","readme":"# Fakegoose\n\nFakegoose is a plugin for simulating queries and seeding collections in \n[Mongoose](https://github.com/Automattic/mongoose) using the \n[Faker](https://github.com/Marak/faker.js) contextual data generation tool. \nFakegoose takes Mongoose schemas and generates the proper dummy data based\non the types and defaults described for on-the-fly queries or seeding\ncollections for testing.\n\n```sh\nnpm install fakegoose\n```\n\n## Command-line Usage\n\n### Seeding the database\n\n```sh\nfakegoose examples/chat-message.js --count 42 --seed mongodb://localhost:27017/test\n```\n\n### Quick JSON documents\n\n```sh\nfakegoose examples/chat-message.js --count 42\n```\n\nWithout the `--seed [mongo_url]` argument, generated documents will be\nprinted with `console.log()`.\n\n**Note:** Fakegoose must be installed globally `install --global` to be used from the command-line. \n\n## Programmatic Usage\n\nFakegoose works like other Mongoose plugins and only effects the\nmodels of schemas it is applied to. Inside the schema, the `fake` \nproperty instructs Fakegoose how to generate fake data. See [Faker](https://github.com/Marak/faker.js)\nfor a list of all methods. If Faker does not have the generator\nyou need, `fake` can also be a function that takes no arguments.\n\n```js\n// models/chat-message.js\nvar mongoose = require('mongoose');\nvar fakegoose = require('fakegoose');\n\nvar chatMessageSchema = new mongoose.Schema({\n  first: {\n    type: String,\n    fake: 'name.firstName'  // calls faker.name.firstName()\n  },\n  last: {\n    type: String,\n    fake: 'name.lastName'   // calls faker.name.lastName()\n  },\n  text: {\n    type: String,\n    fake: 'lorem.paragraph' // calls faker.lorem.paragraph()\n  },\n  date: {\n    type: Date,\n    fake: 'date.past'       // you get the pattern\n  }\n});\n\nchatMessageSchema.plugin(fakegoose);\nmodule.exports = mongoose.model('ChatMessage', chatMessageSchema);\n```\n\nFakegoose adds static methods `fake` (`find` variant) and \n`fakeOne` (`findOne` variant) for querying, and `seed` for\ndatabase population.\n\n### Querying\n\nThe `fake` and `fakeOne` methods are drop-in replacements for\nMongoose's `find` and `findOne` accepting the same arguments\nand using the same chaining interface. \n\n`Model.fake`\n- `fake([conditions]) Query`\n- `fake(conditions[, options]) Query`\n- `fake(conditions[, options], callback:(error, results)) Query`\n\n`Model.fakeOne`\n- `fakeOne([conditions]) Query`\n- `fakeOne(conditions[, options]) Query`\n- `fakeOne(conditions[, options], callback:(error, results)) Query`\n\n```js\n// elsewhere\nvar assert = require('assert');\nvar mongoose = require('mongoose');\nvar ChatMessage = mongoose.model('ChatMessage');\n\nChatMessage.fakeOne({first: 'Chris'}, function(error, message) {\n  if(error) {\n    // this won't be called ever but is good\n    // to include if #fakeOne is ever going\n    // to be changed to #findOne.\n  }\n  assert.equal(message.first, 'Chris');\n});\n```\n\nFakegoose queries will conform to simple conditions, but don't yet\ninterpret `$[g|l]t[e]`, `$in`, or other expressions, but can with\nhelp from viewers like you. Options like `select`, `limit`, `skip`,\nand `lean` work properly, however complicated features such as\naggregation and `populate` do not..yet.\n\n### Seeding\n\n`Model.seed`\n- `Model.seed(count:number[, forceAppend=false], callback:(error))`\n\n`Model.seed` adds `count` documents to the model's collection, passing\nan error to the completion `callback` if there was a Mongoose error.\nBy default if you specify a `count` Fakegoose will only seed **at a maximum**\nthe number of documents necessary to reach the count. So if your collection\nhas 42 records and you call `Model.seed(69, ...)` only 27 documents will be\nadded to the collection. This is done because seeding generally is safe to\nperform multiple times without overfilling the database. To add exactly\n`count` documents, use `Model.seed(420, true, myCallback)`.\n\n## Contributing\n\nContributions are incredibly welcome as long as they are standardly applicable\nand pass the tests (or break bad ones). Tests are written in Mocha and\nassertions are done with the Node.js core `assert` module.\n\n```bash\n# running tests\nnpm run test\n```\n\nFollow me on [Twitter](https://twitter.com/compooter) for updates or just for\nthe lolz and please check out my other [repositories](https://github.com/andrejewski)\n if I have earned it. I thank you for reading.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Ffakegoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrejewski%2Ffakegoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrejewski%2Ffakegoose/lists"}