Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including momog with all npm packages installed. Try it out:

var momog = require("momog")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

momog v1.0.5

Mongoose Model Generator

#MoMoG Mongoose Model Generator as momog A small tool thats help to write mongoose model for mongodb as quick as possible for saving time, and not worry so much about writing model just think about it how it will be look like and just do it in a second.

##Installing

npm install -g momog

##Usage prefix of using it is momog

####The Options :

optionstands for
-nname of the mode
-f or --fieldname of the field
-d or --directorypath to save model

Types:

Shortcutstands for
stringString
numNumber
dateDate
arrArray
idObjectId

####Fields Name Shortcuts:

Shortcutstands for
rrequired
uUnique
sfnot select
defdefault value
refreferrence to other model

##Examples: We Want to create a basic user model with:

  • User name field thats string , required and of course sould be unique
  • Password thats should be string required and not unique also we don't need to select it in any query
  • PhoneNumber thats should be a string not required but unique and set default value for it 00000

Simply you will type

momog -n user -f username string r u -f password string r sf -f phonenumber num u def 00000

and will create

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const userSchema = new Schema({
    username: {
        type: String,
        required: true,
        unique: true
    },
    password: {
        type: String,
        required: true,
        select: false
    },
    phonenumber: {
        type: Number,
        unique: true,
        default: '00000'
    }
});
module.exports = mongoose.model('User', userSchema);

also will generate file with this code in the same directory because we don't specified the directory called user.js

Another Example

we need to create article model with:

  • Title of type string thats should be unique and required
  • Content of the article also string and required
  • Date of the article
  • The Publisher we just need the id
momog -n article -f title string u r -f content string r -f date date r -f publisher id ref user -d models

will generate :

const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const articleSchema = new Schema({
    title: {
        type: String,
        unique: true,
        required: true
    },
    content: {
        type: String,
        required: true
    },
    date: {
        type: Date,
        required: true
    },
    publisher: {
        type: Schema.Types.ObjectId,
        ref: 'user'
    }
});
module.exports = mongoose.model('Article', articleSchema);

will generate file with this code in the directory ./models called article.js

##License: The MIT License

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free