Skip to content

davidbayo10/mongoose-model-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-model-loader

Installation

npm install davidbayo10/mongoose-model-loader --save

Getting started

'use strict'

const mongooseModelLoader = require('mongoose-model-loader');

/**
* @param dirname {String} Full project main path
* @return {Promise}
*/

function init(dirname) {
  const sourcePath = dirname + '{ models directory }';
  return mongooseModelLoader.loader({
    db: 'localhost/name-of-database'
    sourcePath: sourcePath,
    fileExtension: '.model.js',     // .js as default
  });
}

Model file example

// user.model.js

'use strict'

const model = {
  name: {
    type: String,
    required: true,
  },
  surname: String,
  nif: {
    ref: 'Nifs',
  },
  age: Number,
  logs: [
    {
      date: Date,
      ip: String,
    },
  ],
  status: {
    type: String,
    default: 'ON',
  }
}

module.exports = model;

Models are mongoose schema definitions.

For more info: Go to Mongoose Docs

LICENSE

mongoose-model-loader is available under the following licenses:

  • ISC

Copyright 2016 - David Bayo Alcaide

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published