Registry / database / mongo-rest

mongo-rest

JSON →
library3.0.7jsnpmunverified

Express middleware that automatically generates REST API endpoints for Mongoose models. Version 3.0.7 is stable but has not seen updates since 2016. It provides CRUD routes (GET, POST, PUT, DELETE) with optional view rendering and interceptors. Compared to alternatives like express-restify-mongoose, it is simpler but less configurable and no longer actively maintained.

npm install mongo-rest
INSTALL
IMPORT
SIG · MONGO-REST
M
mongo-rest
databasejavascriptv3.0.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MongoRest
const MongoRest = require('mongo-rest')
Uses CommonJS; no default export. Required as a constructor.
mongoRest instance
const mongoRest = new MongoRest(app, options)
new MongoRest(options) without app
First argument must be an Express app instance.

Sets up a basic Express app with mongo-rest exposing REST endpoints for a User model.

const express = require('express'); const mongoose = require('mongoose'); const MongoRest = require('mongo-rest'); const app = express(); mongoose.connect('mongodb://localhost/test'); const mongoRest = new MongoRest(app, { urlPath: '/api/' }); const UserSchema = new mongoose.Schema({ name: String }); const User = mongoose.model('User', UserSchema); mongoRest.addResource('users', User); app.listen(3000); // Now GET /api/users returns list of users, POST /api/users creates a user, etc.
Debug
Known issues
deprecatedPackage not updated since 2016; consider alternatives like express-restify-mongoose or building with express and mongoose directly.
fix
Migrate to a maintained library or implement REST endpoints manually.
affects: >=0.0.0
breakingIn version 2.x, required an Express app as first arg; in 3.x the app argument is still required but options changed.
fix
Ensure you pass (app, options) to the constructor.
affects: >=3.0.0
gotchaaddResource expects a Mongoose model, not a schema. Using a schema will cause runtime errors.
fix
Pass a model (result of mongoose.model('Name', schema)).
affects: >=0.0.0
gotchaDefault urlPath is '/', which can conflict with your other routes. Always specify a unique prefix.
fix
Pass urlPath option, e.g., new MongoRest(app, { urlPath: '/api/' }).
affects: >=0.0.0
deprecatedThe library uses semantic versioning but version numbers in README (1.0.1) are outdated; actual latest is 3.0.7.
fix
Ignore README version references; use npm published version.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: app is not a function
MongoRest constructor requires an Express app as first argument.
fix
new MongoRest(app, options) where app is from express()
Error: Cannot find module 'mongo-rest'
Package not installed or spelled incorrectly.
fix
npm install mongo-rest@3.0.7
TypeError: mongoRest.addResource is not a function
addResource is called on an instance of MongoRest, but wrong import or missing new.
fix
Use: const mongoRest = new MongoRest(app); mongoRest.addResource(...)
Upgrade
Version history
3.0.7latest on npm
Audit
Dependencies
expressrequiredIntegrates with Express app for route registration
mongooserequiredUses Mongoose models to generate REST endpoints
Agent activity
8 hits · last 30 days
node
6
Resources
mongo-rest — npm install mongo-rest · libregistry