【发布时间】:2015-06-15 02:46:00
【问题描述】:
我需要一种方法来存储大量不同的函数,每个函数都有一个唯一的 ID,也许还有一些其他属性,然后我可以查询这些属性并将其带回客户端或服务器以供使用。
保存函数的唯一方法是使用 MongoDB 的 system.js 集合,但我无法通过 Meteor 访问它。
当我尝试在此处实施解决方案时,我似乎可以保存一个函数,但我不知道如何将其恢复并运行它:
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()
【问题讨论】: