1

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 are String, Number, Date, Buffer, Boolean, Mixed, ObjectId and Array.

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?

6
  • Is it for a map/reduce? Commented Feb 19, 2013 at 14:00
  • i simply want to store custom JavaScript functions with each document and retrieve them back. Commented Feb 19, 2013 at 14:18
  • Mongoose plugins can be found by the keyword "mongoose" in NPM, but the far I could see, there isn't anything for the Code class datatype yet. Commented Feb 19, 2013 at 15:14
  • what are you actualy trying to achieve by storing functions in db? Commented Feb 21, 2013 at 10:27
  • @hilarudeens : storing some events in the db to fire when users select them active. Commented Feb 21, 2013 at 12:14

1 Answer 1

1

This module adds function support to Mongoose: https://github.com/aheckmann/mongoose-function

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.