I'm trying to make a design decision.
I'm not well acquainted with either MongoDB or its PHP driver but I'm intrigued by the JavaScript syntax of the stored functions that mongodb use.
Can you tell me whether there is a way to create MongoDB stored functions using PHP?
My reference for creating mongodb stored functions: https://github.com/mongodb/mongo/blob/master/jstests/storefunc.js
It sounds like you are referencing server-side functions.
Creating / updating a server-side function is as easy as updating the system.js
collection:
db.system.js.save( { _id : "foo" , value : function( x , y ){ return x + y; } } );
The problem here is really "using" the server-side functions. First you have to write some kind of awkward update/insert statements. Second, these are not stored procedures. They are not compiled for speed with the intent of running them on the server.
If you use a server-side function for querying it won't use indexes for anything inside of that function. Plus it will use the eval
feature under the hood which can lock up your DB.
Also, there are no triggers, so you can't use these for triggers either.
Overall, there is not a lot of use for server-side functions, which is probably why they get 3 paragraphs in the docs.
If you need advanced query functions look at the new Aggregation Framework. If you're looking for some form of triggers, you will have to roll your own. If you're looking for stored procedures, these are really not it.