1.7.1 ā€¢ Published 7 years ago

hapi-devine-mongodb v1.7.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

hapi-devine-mongodb

Description

šŸ”§ This Hapi plugin loads all schemas in the given directory and registers them as models with Mongoose.

index.js and files starting with a _ are ignored

Install hapi-devine-mongodb

yarn add hapi-devine-mongodb

Usage

register this module as a plugin in Hapi

server.register({

  register: require(`hapi-devine-mongodb`),

  options: {
    connectionString: 'mongodb://localhost/test' // mongodb connection string (required)
    path: path.join(__dirname, `schemas`) // schema directory (required)
    log: true // provide logs (optional, default: true)
  }

}, pluginHandler);

Schema Example

files in the schema directory should look like this

hapi-devine-mongodb automatically adds 'modified' & 'created' timestamps + 'isActive' (default: true) to the Model

const schema = {

  username: {
    type: String,
    required: true,
    unique: true
  },

  email: {
    type: String,
    required: true,
    unique: true
  }

};

// optional props collectionName & name (model name) & plugins
module.exports = {schema};

hapi-devine-mongodb defaults to the name of the file as the model name, Mongoose defaults to modelname (lowercase) + 's' for the collection name.

optional properties

  • name (String): the name of the model
  • collectionName (String): the name of the collection (ex. Feedback, there is no 'feedbacks', provide 'feedback')
  • plugins (Array): an array of mongoose plugins

example:

  • filename: 'Tweet.js'
  • model name: 'Tweet'
  • collection name: 'tweets'

License

MIT

1.7.1

7 years ago

1.7.0

7 years ago

1.6.2

7 years ago

1.6.1

7 years ago

1.6.0

7 years ago

1.5.1

7 years ago

1.5.0

7 years ago

1.4.4

7 years ago

1.4.3

7 years ago

1.4.2

7 years ago

1.4.0

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago