A lightweight utility (v1.0.0, no recent updates) that extends a Mongoose schema by merging its fields with additional definitions. Unlike mongoose-extend-schema, native Mongoose does not provide a built-in schema inheritance method; this package offers a simple shallow merge approach. It is installed from npm, requires Node >=8.2.1 and Mongoose as a peer dependency. While straightforward, it has known issues: it only shallow-copies schema fields, does not copy indexes or other schema options, and can cause silent overrides if field names conflict. Use with caution for simple schema extension needs.
npm install mongoose-extend-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to extend a Mongoose schema using mongoose-extend-schema, including connection and saving a document.
Manually deep-merge definitions or avoid nested structures.
Explicitly pass options as the third argument to extendSchema: extendSchema(base, defs, base.options).
Add indexes manually to the extended schema after creation.
Ensure field names are unique or carefully review overrides.
Use the 'options' argument to set a schema name: extendSchema(base, defs, { _id: false, id: false, ... })Replace const { extendSchema } = require('mongoose-extend-schema'); with const extendSchema = require('mongoose-extend-schema');Ensure extendSchema returns a valid mongoose.Schema instance: const schema = extendSchema(...); mongoose.model('X', schema);Check that the first argument is a valid mongoose.Schema instance, e.g., const base = new mongoose.Schema({...}); extendSchema(base, {...});