easy-mongoose

0.1.0 • Public • Published

Mongoose Builder

Overview

Convenience library for building Mongoose schemas and models, and working with connections

Usage

Install:

npm install easy-mongoose

To create a schema:

 
var typeBuilder = require('easy-mongoose').typeBuilder;
 
// Specify a namespace for the schemas
var schemas = typeBuilder.schemas('myNamespace');
 
schemas
 
// Create two schema elements, "adult" and "child"
  ('child', {
    name: {type: String, required: true, unique: true},
    description: String
  })
  ('adult', {
    name: {type: String, required: true, unique: true},
    children: [
      schemas.ref('child')
    ]
  })
 
// Export "adult" as a model element, but not "child"
  (['adult']);

Then to consume those schemas as models:

var dbConnection = require('easy-mongoose').dbConnection;
 
dbConnection(dbUrl, 'myNamespace').then(function (db) {
  var Adult = db.getModel('adult');
  // ...
}).catch(function(e){
  // oh noes
});
 

Readme

Keywords

none

Package Sidebar

Install

npm i easy-mongoose

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • christyharagan