{"id":13607701,"url":"https://github.com/waptik/mongoose-cli","last_synced_at":"2025-09-16T18:31:08.869Z","repository":{"id":34943321,"uuid":"190049775","full_name":"waptik/mongoose-cli","owner":"waptik","description":"A CLI that generates models,migrations and seeders for mongoosejs","archived":false,"fork":false,"pushed_at":"2023-04-24T19:15:05.000Z","size":2474,"stargazers_count":20,"open_issues_count":18,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-02T20:42:41.551Z","etag":null,"topics":["cli","migrations-generator","mongoosejs","seed-generator","seeder"],"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/waptik.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2019-06-03T17:21:14.000Z","updated_at":"2024-07-08T14:11:48.000Z","dependencies_parsed_at":"2024-01-16T23:30:20.267Z","dependency_job_id":"b26d1d47-c269-40d2-b0f7-5da288fe15af","html_url":"https://github.com/waptik/mongoose-cli","commit_stats":{"total_commits":58,"total_committers":7,"mean_commits":8.285714285714286,"dds":"0.31034482758620685","last_synced_commit":"5b61fcd9da6ab68eede25b06fadce9fa153a6deb"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waptik%2Fmongoose-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waptik%2Fmongoose-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waptik%2Fmongoose-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/waptik%2Fmongoose-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/waptik","download_url":"https://codeload.github.com/waptik/mongoose-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233283697,"owners_count":18652863,"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":["cli","migrations-generator","mongoosejs","seed-generator","seeder"],"created_at":"2024-08-01T19:01:20.847Z","updated_at":"2025-09-16T18:31:03.415Z","avatar_url":"https://github.com/waptik.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eWelcome to mongoosejs-cli 👋\u003c/h1\u003e\n\u003cp\u003e\n  \u003ca href=\"https://badge.fury.io/js/mongoosejs-cli\"\u003e\n    \u003cimg alt=\"npm version\" src=\"https://badge.fury.io/js/mongoosejs-cli.svg\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/waptik/mongoose-cli#readme\"\u003e\n    \u003cimg alt=\"Documentation\" src=\"https://img.shields.io/badge/documentation-yes-brightgreen.svg\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/waptik/mongoose-cli/graphs/commit-activity\"\u003e\n    \u003cimg alt=\"Maintenance\" src=\"https://img.shields.io/badge/Maintained%3F-yes-green.svg\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/waptik/mongoose-cli/blob/master/LICENSE\"\u003e\n    \u003cimg alt=\"License: MIT\" src=\"https://img.shields.io/badge/License-MIT-yellow.svg\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://travis-ci.org/waptik/mongoose-cli\"\u003e\n    \u003cimg alt=\"Build Status\" src=\"https://travis-ci.org/waptik/mongoose-cli.svg?branch=master\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://greenkeeper.io/waptik/mongoose-cli\"\u003e\n    \u003cimg alt=\"Greenkeeper badge\" src=\"https://badges.greenkeeper.io/waptik/mongoose-cli.svg\" target=\"_blank\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n[![npm](https://nodei.co/npm/mongoosejs-cli.png)](https://www.npmjs.com/package/mongoosejs-cli)\n\n### 🏠 [Homepage](https://github.com/waptik/mongoose-cli)\n\n![mongoosejs-cli logo](https://github.com/waptik/mongoose-cli/blob/master/.github/images/logo.svg)\n\n## Table of Contents\n\n- [Introduction](#introduction)\n- [Prerequisites](#prerequisites)\n- [Installation](#installation)\n- [Usage](#usage)\n- [CLI Options](#options)\n- [Contributing](#contributing)\n- [FAQ](#faq)\n- [Documentation](#documentation)\n- [Credits](#credits)\n- [License](#license)\n\n## Introduction\nThis package, Mongoosejs-cli, is a package for nodejs to help generate and run migrations and seeders for mongoosejs with ease.\n\n\u003eNote that this is an unofficial CLI package for [mongoosejs](https://github.com/Automattic/mongoose).\n\n## Prerequisites🔨\n\n- node \u003e=11.0.0\n- yarn \u003e= 1.16.0 || npm \u003e= 6.0.0\n- mongoosejs \u003e= 5.5.12\n\n## Installation🛠\n\n### Globally\nThere are two ways to of installing and using this package:\n\n```sh\nyarn global add mongoosejs-cli\n```\n\n\u003e - Usage\n\u003e   - mongoose\n\n### Locally\n\n```sh\nyarn add mongoosejs-cli\n```\n\n\u003e - Usage\n\u003e   - npx mongoosejs-cli\n\n### Note 📓\nIt is recommended to install the package in your project(local). We'll be using the local approach in the following examples.\n\n\n## Usage\n\nMake sure you have mongoose already installed in your project before proceeding.\n\n### To display list of options that the command has, do the following\n\n```sh\nnpx mongoosejs-cli\n```\nYou'll see the following on your terminal:\n\n```sh\nMongoosee CLI [Node: 11.10.0, CLI: 1.0.5, ODM: 5.5.12]\n\nmongoose [command]\n\nCommands:\n  mongoose db:migrate                        Run pending migrations\n  mongoose db:migrate:status                 List the status of all migrations\n  mongoose db:migrate:undo                   Reverts a migration\n  mongoose db:migrate:undo:all               Revert all migrations ran\n  mongoose db:seed                           Run specified seeder\n  mongoose db:seed:undo                      Deletes data from the database\n  mongoose db:seed:all                       Run every seeder\n  mongoose db:seed:undo:all                  Deletes data from the database\n  mongoose init                              Initializes project\n  mongoose init:config                       Initializes configuration\n  mongoose init:migrations                   Initializes migrations\n  mongoose init:models                       Initializes models\n  mongoose init:seeders                      Initializes seeders\n  mongoose migration:generate                Generates a new migration file             [aliases: migration:create]\n  mongoose model:generate                    Generates a model and its migration            [aliases: model:create]\n  mongoose seed:generate                     Generates a new seed file                       [aliases: seed:create]\n\nOptions:\n  --help     Show help                                                                                    [boolean]\n  --version  Show version number                                                                          [boolean]\n```\n\n### To initialize the project\n\nWe recommend that after viewing the list of commands, first thing to do, is to generate the required files and directories needed to get started. It can achieved by entering the following command.\n\n```sh\nnpx mongoosejs-cli init\n```\n\nThis will generate the following:\n\n```sh\n config/\n  config.json\n models/\n  index.js\n migrations/\n seeders/\n```\n\n\n- config/ =\u003e the directory containing all your configuration files\n  -  config.json =\u003e the default configuration files that contains the database connection strings based on the environment(NODE_ENV). You can add extra environments as well.\n- models/ =\u003e the directory that contains all your mongoose models you generated through the package\n  -  index.js =\u003e this file does the database connection and imports all your models\n- migrations/ =\u003e directory containing all your migration files\n- seeders/ =\u003e directory containing all your seed files\n\n## Options\n\n### Changing path\n\nBy default, mongoosejs-cli generates the migrations, seeders and models directories and files in the root directory of your project. To change this behaviour, create a new file called `.mongooserc` manually or use the the following command:\n\n```sh\ntouch .mongooserc\n```\n\nand paste the following code inside the new created file\n\n```js\nconst path = require('path');\n\nmodule.exports = {\n  'config': path.resolve('config', 'database.json'),\n  'models-path': path.resolve('db', 'models'),\n  'seeders-path': path.resolve('db', 'seeders'),\n  'migrations-path': path.resolve('db', 'migrations')\n}\n```\n\nNow the CLI will look for its\n- configuration settings inside ./config/database.json\n- models files inside ./db/models/\n- migration files inside ./db/migrations/\n- seed files inside ./db/seeders/\n\n### Configuration file\n\nBy default the CLI will try to use the file `config/config.js`. You can modify that path either via the `--config` flag or via the option mentioned earlier. Here is how a configuration file might look like (this is the one that `npx mongoosejs-cli init` generates):\n\n```json\n{\n  \"development\": {\n    \"database\": {\n      \"url\": \"mongodb://localhost/mongoose_dev\",\n      \"options\": {\n        \"useNewUrlParser\": true\n      }\n    }\n  },\n  \"test\": {\n    \"database\": {\n      \"url\": \"mongodb://localhost/mongoose_test\",\n      \"options\": {\n        \"useNewUrlParser\": true\n      }\n    }\n  },\n  \"production\": {\n    \"database\": {\n      \"protocol\": \"mongodb\",\n      \"username\": \"root\",\n      \"password\": \"password\",\n      \"name\": \"database_production\",\n      \"host\": \"localhost\",\n      \"port\": \"\",\n      \"options\": {\n        \"useNewUrlParser\": true\n      }\n    }\n  }\n}\n```\n\n\n### Configuration for connecting over SRV\n\nIn case you are using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) or any other services that supports srv, kindly remove database name known as `\"name\"` from the database main object and assign its value to a new string called `\"dbName\"` in the options object, such as the following.\n\n```json\n{\n\n  \"production\": {\n    \"database\": {\n      \"protocol\": \"mongodb+srv\",\n      \"username\": \"root\",\n      \"password\": \"password\",\n      \"host\": \"subdomain.mongodb.com\",\n      \"port\": \"\",\n      \"options\": {\n        \"useNewUrlParser\": true,\n        \"dbName\": \"database_production\",\n      }\n    }\n  }\n}\n```\n\nIn case you want to use a url string instead, do the following\n\n```json\n{\n\n  \"production\": {\n    \"database\": {\n      \"url\": \"mongodb+srv://root:password@subdomain.mongodb.com/database_production\",\n      \"options\": {\n        \"useNewUrlParser\": true,\n        \"dbName\": \"database_production\",\n      }\n    }\n  }\n}\n```\n\nMore coming soon...\n\n## Contributing🤝\nIf you love this package, there are different ways in which you can contribute.\n\n\u003cdetails\u003e\n\u003csummary\u003e 👍 Show you Support\u003c/summary\u003e\n\nGive a ⭐️ if this project helped you!\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e General Issues or Feature Requests\u003c/summary\u003e\n\n### Reporting issues or bugs🐛\n\n\u003e Please make sure to read the full guidelines. Your issue may be closed without warning if you do not.\n\nBefore reporting a new issue, kindly check [issues page](https://github.com/waptik/mongoose-cli/issues) to see if similar issues haven't been solved yet. Else, go ahead and create a new issue.\n\n\u003e Github issues should follow specified template. When you start creating a new issue, an empty template will be made available to you.\n\nPlease make sure issue you are reporting is strictly related to Mongoosejs CLI.\n\n### Proposing new features\nIf you want to propose new features to Mongoosejs CLI, you may ignore issue template. You still need to clearly state new feature. Feature request should give various examples, API suggestions and references to support idea behind it.\n\n### Fixing Bugs or Implementing Features\n\n1. Preparing your environment\n\nStart by cloning Mongoosejs CLI repo\n\n```sh\n$ git clone git@github.com:waptik/mongoose-cli.git\n\n$ git clone https://github.com/waptik/mongoose-cli.git # Using HTTPS\n```\n\nMake sure you have all required dependencies, you will need\n\n- Node v10 or above\n- Yarn v1.16 or above\n\nNow go to cloned repository folder\n\n```sh\n$ cd /path/to/cloned/repository\n```\n\nInstall required modules\n\n```sh\n$ yarn\n```\n\n### Running tests\n\n```sh\n$ yarn test\n```\n\nTest can take about 7 to 10 minutes to finish, subjected to hardware configuration.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eImproving Documentation\u003c/summary\u003e\n\nIf you want to improve or expand our documentation you can start with this readme file.\n\u003c/details\u003e\n\n## FAQ\nThe Mongoosejs Command Line Interface (CLI) Frequently Asked Question\n\n### Initialize mongoose to create necessary files in the project\n```\n$ npx mongoosejs-cli init\n```\n\n### How can I generate a model?\nSpecify model name with `--name` argument. List of table fields can be passed with `--attributes` option. Note that the datatypes are using [Mongoose SchemaTypes](https://mongoosejs.com/docs/schematypes.html) when defining them using the CLI.\n```\n$ npx mongoosejs-cli model:create --name User --attributes name:String,state:Boolean,birth:Date,card:Number\n```\n\nYou can create your own custom datatypes as plugins after the model file has been generated for you. Refer to [Mongoose Plugins](https://mongoosejs.com/docs/plugins.html), on how to do so.\n\n### How can I create a migration?\nSpecify migration name with `--name` argument\n```\n$ npx mongoosejs-cli migration:create --name \u003cmigration_name\u003e\n```\n\n### How do call/use a model defined?\nYou can call/use a model(eg: Player) by doing the following:\n```js\nconst models = require('path_to_models_folder');\n\nconst players = await models.Player.find({});\n\nconsole.log(players) // will print players collection\n```\n\n### What is the command to execute all migrations?\n```\n$ npx mongoosejs-cli db:migrate\n```\n### How can I make a migrations rollback?\n```\n$ npx mongoosejs-cli db:migrate:undo:all\n```\n\n### How can I create a seeder?\nSpecify seeder name with `--name` argument\n```\n$ npx mongoosejs-cli seed:create --name \u003cseeder_name\u003e\n```\n\n### How can I run the seeders?\n```\n$ npx mongoosejs-cli db:seed:all\n```\n\n### How can I make the seeders rollback?\n```\n$ npx mongoosejs-cli db:seed:undo:all\n```\n\n### Do you have an example of how the structure of the project look like?\nYes. Please check the [examples](https://github.com/waptik/mongoose-cli/blob/master/examples/) folder in this project. Screenshots can also be found [here](https://github.com/waptik/mongoose-cli/blob/master/.github/images/screenshots)\n\n\n## Documentation📓\n\n- [Mongoosejs Documentation](https://mongoosejs.com/docs/index.html)\n- [CLI Options](#options)\n- [Frequently Asked Questions](#faq)\n\n\n## Credits👌\nThis package would not have been made possible if not for the following:\n- [Mongoosejs](https://github.com/Automattic/mongoose) Contributors and maintainers for the awesome ORM specially for mongodb on nodejs\n- [Sequelize](https://github.com/sequelize) for their [CLI](https://github.com/sequelize/cli), which Mongoosejs-cli structure was heavily based on.\n- [Kefranabg](https://github.com/kefranabg), for his [readme-md-generator](https://github.com/kefranabg/readme-md-generator) package which generated the skeleton for this readme file.\n- Nodejs, Yarnpkg, NPM etc...\n\n## License📝\n\nCopyright © 2019 [Stephane Mensah](https://github.com/waptik).\u003cbr /\u003e\nThis project is [MIT](https://github.com/waptik/mongoose-cli/blob/master/LICENSE) licensed.\n\n## Author\n\n👤 **Stephane Mensah**\n\n* Twitter: [@_waptik](https://twitter.com/_waptik)\n* Github: [@waptik](https://github.com/waptik)\n\n\n***\n_This README was generated with ❤️ by [readme-md-generator](https://github.com/kefranabg/readme-md-generator)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaptik%2Fmongoose-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwaptik%2Fmongoose-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwaptik%2Fmongoose-cli/lists"}