I want to store functions in MongoDB (don’t ask why, I just want to).
If I go into meteor mongo
and do:
db.myCollection.insert({ "myFunc": function(num1, num2) { return num1 + num2 } })
I can retrieve my last insert and directly run the function stored on it quite easily and naturally:
db.myCollection.find().sort({$natural:-1})[0].myFunc(10,5)
returns 15 in meteor mongo
How do I do this equivalent code in Meteor’s server-side or client-side code? When I go to retrieve the document and the myFunc
property, it returns the function as a string, in both the server and client code. I’ve read that eval
is not a good way to run functions that are in the form of strings.