Registry / database / fastify-mongoose-rest

fastify-mongoose-rest

JSON →
library5.1.1jsnpmunverified

Fastify plugin that generates RESTful CRUD routes from Mongoose models. Current version 5.1.1, actively maintained. It auto-creates routes for list, search, details, create, modify, delete, and insert-many operations. Supports pagination, OpenAPI documentation, request validation via JSON Schema, and TypeScript definitions. Compared to alternatives like fastify-restify or mongoose-rest-store, this integrates tightly with Fastify and Mongoose and provides built-in search and populate capabilities.

npm install fastify-mongoose-rest
INSTALL
IMPORT
SIG · FASTIFY-MONGOOSE-R
F
fastify-mongoose-rest
databasejavascriptv5.1.1
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.

default
import FastifyMongooseRest from 'fastify-mongoose-rest'
const FastifyMongooseRest = require('fastify-mongoose-rest').default
Default export; CJS require works directly without .default.
FastifyMongooseRestOptions
import type { FastifyMongooseRestOptions } from 'fastify-mongoose-rest'
const { FastifyMongooseRestOptions } = require('fastify-mongoose-rest')
TypeScript users should import the type separately; it cannot be destructured from CJS require.

Create a Fastify app with CRUD routes for a Mongoose Cat model using fastify-mongoose-rest.

import FastifyMongooseRest from 'fastify-mongoose-rest'; import Fastify from 'fastify'; import mongoose from 'mongoose'; const catSchema = new mongoose.Schema({ name: String, age: Number }); const Cat = mongoose.model('Cat', catSchema); const app = Fastify(); const rest = FastifyMongooseRest('cats', Cat, { logResponses: true, totalCountHeader: true, }); app.route(rest.list); app.route(rest.create); app.route(rest.details); app.route(rest.modify); app.route(rest.delete); await app.listen({ port: 3000 });
Debug
Known issues
breakingIn version 5.x, the route method signatures changed. You must now call fastify.route(rest.list) instead of fastify.get(...).
fix
Use fastify.route(rest.list) for all route registrations.
affects: >=5.0.0
deprecatedThe option `logResponses` default is true; in older versions it was false. Not setting it explicitly may expose data in logs.
fix
Set logResponses: false if you do not want to log response bodies.
affects: >=5.0.0
gotchaMongoose model must be fully compiled before passing to FastifyMongooseRest. Dynamic imports or lazy models cause undefined errors.
fix
Ensure the model is created and exported before calling FastifyMongooseRest.
affects: *
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'find')
Mongoose model is not defined or compiled when passed to FastifyMongooseRest.
fix
Check that the model is correctly imported and is a Mongoose Model instance.
FastifyMongooseRest is not a function
Using named import instead of default import.
fix
Use import FastifyMongooseRest from 'fastify-mongoose-rest'.
fastify.route is not a function
Using an older version of Fastify that does not support the route method, or the plugin is not registered.
fix
Upgrade Fastify to version 4.x+ and ensure the plugin is imported correctly.
Upgrade
Version history
5.1.1latest on npm
Audit
Dependencies
fastifyrequiredpeer dependency required for plugin to register routes
mongooserequiredpeer dependency required for model-based route generation
Agent activity
10 hits · last 30 days
node
8
Resources
fastify-mongoose-rest — npm install fastify-mongoose-rest · libregistry