Mongoose resource


var express = require('express');
var mongoose = require('mongoose');
var mr8 = require('mr8')(mongoose);
var app = express();
mongoose.connect('mongodb://localhost/test', function() {
    mr8.applyTo(app, {options...}); // See lib/options.js for options reference 
  • GET http://hostname:port/mr8/Thing - get Things
  • GET http://hostname:port/mr8/Thing/1 - get Thing with _id = 1
  • POST http://hostname:port/mr8/Thing - create Thing
  • PUT http://hostname:port/mr8/Thing/1 - update Thing with _id = 1
  • DELETE http://hostname:port/mr8/Thing/1 - delete Thing with _id = 1

See lib/queryBuilders for supported query modifiers such as where, limit, skip, etc.


mr8 object contains ee property which is an EventEmitter instance. After each affecting request (POST, PUT, DELETE) it emits two events: %action%:post and %action%:post:%name, where %action% is action name ('create', 'update', 'delete' respectievely) and %name% is affected model name.

// POST http://hostname:port/mr8/Thing'create:post', function(namedata) {
    // 'name' is a model name ('Thing' in our example) 
    // 'data' is the created Thing instance 
// PUT http://hostname:port/mr8/Thing/1'update:post:Thing', function(data) {
    // 'data' is the updated Thing instance