I need a way to store lots and lots of different functions, each with a unique ID and perhaps some other properties that I can then query for and bring back to the client or server for use.
The only way to save functions is with MongoDB's system.js
collection, but I am unable to access it via Meteor.
When I try to implement the solution here I can seemingly save a function but I don't know how to bring it back and run it:
How do I access mongos db.system.js in meteor?
// on /server
var myDB = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
systemJS = myDB.collection('system.js');
systemJS.save({
_id: "echoFunction",
value : function(x) { return x; }
},
function (err, inserted) {
console.log("error: ", err);
console.log("number of docs inserted: ", inserted);
}
);
systemJS.save({
_id : "myAddFunction" ,
value : function (x, y){ return x + y; }
},
function (err, inserted) {
console.log("error: ", err);
console.log("number of docs inserted: ", inserted);
}
);
// always causes the server to crash
// systemJS.findOne()
// returns undefined for db
// db.LoadServerScripts()