node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »


Build Status Coverage Status NPM Version Dependency Status NPM Downloads Issues API Documentation


Provides some convenience functions that can bridge mongoose and your REST endpoints. Nothing special really.

How to get started:

npm install mongoose-rest-helper


The following illustrates a typical use case where we map CRUD functions to the mongoose-rest-helper. This is verbose, you could easily create this for all your models.

mongooseRestHelper = require 'mongoose-rest-helper'
module.exports = class RoleMethods
  constructor:(@model) ->

Return all objects (with pagination, and scoping through accountId)

  all: (accountId,options = {},cb = ->) =>
    return cb new Error "accountId parameter is required." unless accountId
    settings = 
          accountId : mongooseRestHelper.asObjectId accountId
        defaultSort: 'name'
        defaultSelect: null
        defaultCount: 1000
    mongooseRestHelper.all @model,settings,optionscb

Get an entity for it's id

  get: (id,options = {}, cb = ->) =>
    return cb new Error "id parameter is required." unless id
    mongooseRestHelper.getById @model,id,null,optionscb

Destroy an entity

  destroy: (id, options = {}, cb = ->) =>
    return cb new Error "id parameter is required." unless id
    settings = {}
    mongooseRestHelper.destroy @model,idsettings,{}cb

Create an entity

  create:(accountId,objs = {}, options = {}, cb = ->) =>
    return cb new Error "accountId parameter is required." unless accountId
    settings = {}
    objs.accountId = mongooseRestHelper.asObjectId accountId
    mongooseRestHelper.create @model,settings,objs,options,cb

Update an entity

  patch: (id, obj = {}, options = {}, cb = ->) =>
    settings =
    mongooseRestHelper.patch @model,idsettingsobjoptionscb


  • npm install
  • grunt watch
  • grunt deploy

See also

and additionally

Contributing to mongoose-rest-helper

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the package.json, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2013-2014 Martin Wawrusch See LICENSE for further details.