title: How to store JavaScript functions into documents in mongoose?
body: <p>I need to store some data and associated <code>functions</code> into the <code>mongodb document</code>.</p>
  
  <pre><code>{name:"data1",event:function(){ /* some code */ }}
  {name:"data2",event:function(){ /* some other code */ }}
  </code></pre>
  
  <p>i am using <code>mongoose.js</code> <code>ORM</code> for my project. How should i write my <code>schema</code> for this?</p>
  
  <p>quoting from the mongoose <a href="http://mongoosejs.com/docs/guide.html" rel="nofollow">guide</a></p>
  
  <blockquote>
    <p>The permitted <code>SchemaTypes</code> are <code>String</code>, <code>Number</code>, <code>Date</code>, <code>Buffer</code>,
    <code>Boolean</code>, <code>Mixed</code>, <code>ObjectId</code> and <code>Array</code>.</p>
  </blockquote>
  
  <p>But if you check with the <code>datatypes</code> allowed by <code>mongodb</code>, you can find ways to store js function as mentioned in <a href="http://mongodb.github.com/node-mongodb-native/api-articles/nodekoarticle1.html#mongo-db-data-types" rel="nofollow">mongo-db-data-types-article</a></p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>I couldnt find the above datatype on mongoose. Any ideas?</p>