Reputation: 1346
There are a couple of examples of how to create "stored procedures" in MongoDB (here is one) but they only show how to add the code directly, for example in the mongo shell. For any nontrivial stored procedure one would want to store the code in a .js file and 'import' the file into MongoDB. That way it can be easily edited, versioned, etc.
Is there a way to do this?
Upvotes: 1
Views: 1328
Reputation: 239
You can use following syntax:
$ mongo mydb import.js
And writing import instructions inside a script, i.e:
var myfunc = function(x, y){ return x + y; }}
db.system.js.save({_id:"myfunc", value: myfunc);
Upvotes: 3