Plugin for Mongoose that adds support for storing and retrieving JavaScript functions as a schema type. Version 0.1.0 is stable but appears to be in maintenance mode with no recent updates. Unlike storing functions as strings, this plugin enables direct execution of stored functions after retrieval. It monkey-patches Mongoose's schema types, which may cause compatibility issues with newer Mongoose versions. The package is designed for Mongoose 3.x/4.x and requires a separate Mongoose instance.
npm install mongoose-functionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to register the plugin, define a schema with Function type, store a function, and retrieve/execute it.
Upgrade to Mongoose 5+ and avoid using this plugin, or pin Mongoose to version 4.x.
Store any referenced closure variables separately as document properties.
Always invoke the plugin at the top of your application, before any model definitions.
Use with caution; consider alternatives like storing functions as strings or using eval.
Ensure mongoose is installed and pass the mongoose instance: require('mongoose-function')(require('mongoose'));Invoke require('mongoose-function')(mongoose) after requiring mongoose but before any model definitions.