I have a simple JS class:
var User = function(id){
this._id = id;
this.sayHello = function (){
return "hello";
}
}
Then I go to the repository in MongoDB using the default Node.js driver:
users.insert(new User(1));
Finally, I retrieve the user and try to execute the function:
users.findOne({_id:1}, function(err, item) {
console.log("Say hello: " + item.sayHello());
});
I get the following error, which is really confusing:
throw err;
^
TypeError: Object
I completely lost it. I realized that MongoDB stores both JS functions and as-is properties. If this is not the case, can you recommend how I can get around this?
Thank!
source
share