I am trying to save a javascript object with functions,but facing an error. Here is the code:
var mongo = require('mongodb');
createObject = function(){
var data = {_id:1,"name":"object",
"fun":new mongo.Code("function fun() {print(1)}")};
db.collection("objects").insert(data,function(err,result){
console.log(err);
console.log(result);
});
}
getObject = function(){
var f = db.collection("objects").findOne();
f.fun();
}
And the error :
throw err;
^
TypeError: Object #<Object> has no method 'fun'
When I checked mongodb, it is saving "fun" function. But not executed when retrieved from mongo ?
Thanks in advance.