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.

database
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 export; CJS require works directly without .default.

import FastifyMongooseRest from 'fastify-mongoose-rest'

TypeScript users should import the type separately; it cannot be destructured from CJS require.

import type { FastifyMongooseRestOptions } from 'fastify-mongoose-rest'

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 footguns
breakingIn version 5.x, the route method signatures changed. You must now call fastify.route(rest.list) instead of fastify.get(...).
deprecatedThe option `logResponses` default is true; in older versions it was false. Not setting it explicitly may expose data in logs.
gotchaMongoose model must be fully compiled before passing to FastifyMongooseRest. Dynamic imports or lazy models cause undefined errors.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
9 hits · last 30 days
gptbot
3
mj12bot
1
Resources