As I heard, mongoDB can store internal procedures.
How can I use it?
Official Help is very short.
Can I use stored proc. to implement small logic on this layer?
Same as Postgres pl/pgSQL.
As I heard, mongoDB can store internal procedures.
How can I use it?
Official Help is very short.
Can I use stored proc. to implement small logic on this layer?
Same as Postgres pl/pgSQL.
The duplicate question ( MongoDB Stored Procedure Equivalent ) does explain that you can store a procedure within MongoDB that can be called via the eval()
command, however, it doesn't really explain why this is a bad thing.
Eval is a direct access to an, almost, unrestricted JS environment called from MongoDB's C++ code. Good to also mention that injection through unescaped parameters is very easy.
They are not stored procedures that work within MongoDBs own runtime (unlike the stored procedures you are thinking of) the JS engine is run from MongoDB, MongoDB is not programmed in JS; it is programmed in C++.
They are only available from a JS context, not from MongoDB's C++ context.
By default they can take global lock even with the nolock
option set, it all depends upon the operations you call and the JS in itself is extremely slow in comparison to native MongoDB runtime.
As such:
Can I use stored proc. to implement small logic on this layer?
No. It is actually implemented on a third layer, separate from MongoDB.
MongoDB is designed to run this stuff from client side, there is a 90% chance you will get no real benefits by using "stored procedures". In fact in many ACID databases they are heavily abused and used in such a way that actually slows down applications and makes them more prone to failure. So you need to think very carefully about whether you really "need" them or not.