mongodb - Where and how to store functions in Meteor? Or how to use system.js? -


i need way store lots , lots of different functions, each unique id , perhaps other properties can query , bring client or server use.

the way save functions mongodb's system.js collection, unable access via meteor.

when try implement solution here can seemingly save function don't know how bring , run it:

how 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);   } );  // causes server crash // systemjs.findone()  // returns undefined db // db.loadserverscripts() 

well, found very ugly way of getting work:

i put /server/fixtures.js

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);   } );  var arg = "10, 5";  var mongofuncname='myaddfunction';  var string = 'db.loadserverscripts(); return ' + mongofuncname+ '(' + arg + ');';  console.log(string);  mydb.eval(string, function (err, mongofuncreturndata) {   console.log("error: ", err);   console.log("mongofuncreturndata: ", mongofuncreturndata); });  // counting number of functions in system.js mydb.eval("db.system.js.count();", function (err, mongofuncreturndata) {   console.log("error: ", err);   console.log("mongofuncreturndata: ", mongofuncreturndata); });  // finding , retrieving stored function via _id mydb.eval("db.system.js.findone({_id: 'myaddfunction'});", function (err, mongofuncreturndata) {   console.log("error: ", err);   console.log("mongofuncreturndata: ", mongofuncreturndata); }); 

holy hell ugly. i'm hoping there better way this.

i'm concerned fact if implement obvious hack, when update rolls around compromise system on update.

also take note function definitions still have string. if aren't string, won't saved (only _id gets saved).


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -