Reputation: 27845
I need to store some data and associated functions
into the mongodb document
.
{name:"data1",event:function(){ /* some code */ }}
{name:"data2",event:function(){ /* some other code */ }}
i am using mongoose.js
ORM
for my project. How should i write my schema
for this?
quoting from the mongoose guide
The permitted
SchemaTypes
areString
,Number
,Date
,Buffer
,Boolean
,Mixed
,ObjectId
andArray
.
But if you check with the datatypes
allowed by mongodb
, you can find ways to store js function as mentioned in mongo-db-data-types-article
Code class a special class that let’s you store javascript functions in Mongo DB, can also provide a scope to run the method in
I couldnt find the above datatype on mongoose. Any ideas?
Upvotes: 1
Views: 4240
Reputation: 10780
This module adds function support to Mongoose: https://github.com/aheckmann/mongoose-function
Upvotes: 1