A mongoose manager wrapper that provides some common utilities and extends it to support promises.
This package is no longer going to be maintained. Teams have chosen to use the Mongoose directly because it allows them to customize their implementation as they choose and it's less prescriptive.
The Spur Framework is a collection of commonly used Node.JS libraries used to create common application types with shared libraries.
Visit NPMJS.org for a full list of Spur Framework libraries >>
$ npm install spur-mongoosemanager --save
spur = require "spur-ioc"
spurCommon = require"spur-common"
spurMongoosemanager = require "spur-mongoosemanager"
module.exports = ()->
ioc = spur.create("demo")
# register folders in your project to be autoinjected
ioc.registerFolders __dirname, [
"demo"
]
ioc.merge(spurCommon())
ioc.merge(spurMongoosemanager())
ioc
Definition of a MongoDB schemea for a diner.
module.exports = (MongooseSchema, MongooseModel, config, MongooseManager, Moment)->
new class DinerModel extends MongooseModel
constructor:->
super
@_model = @createModel()
createModel:()->
# Define a schema
schema = new MongooseSchema {
_id:
type: Number
required: true
unique: true
index: true
firstName:
type: String
trim: true
lastName:
type: String
trim: true
}
schema.virtual("globalId").get ()->
this._id
schema.set 'toJSON', { virtuals: true }
MongooseManager.model 'Diner', schema
createObject: (globalId, firstName, lastName)->
{
GlobalId: globalId
firstName: firstName
lastName: lastName
}
Service that uses the mongodb diner model created above.
module.exports = (Diner, Promise) ->
new class DinerService
getDiner: (id)->
Diner
.findOneAsync({ _id: id })
.then (diner)->
diner
.error (error)->
Logger.error(error)
{}
injector = require "./src/injector"
injector().inject (MongooseManager)->
# Initiate the connection
MongooseManger.connect()
Please send in pull requests and they will be reviewed in a timely manner. Please review this generic guide to submitting a good pull requests. The only things we ask in addition are the following:
- Please submit small pull requests
- Provide a good description of the changes
- Code changes must include tests
- Be nice to each other in comments. 😇
The majority of the settings are controlled using an EditorConfig configuration file. To use it please download a plugin for your editor of choice.
To run the test suite, first install the dependancies, then run npm test
$ npm install
$ npm test