Advantages and disadvantages of Stored Procedure equivalents

Hi Xavier - I think you may have misunderstood me- MongoDB almost never runs JS on the server, certainly not from system.js. loadServerScripts is not running them on the server - it’s running them in your shell, on your local computer, its just loading js code from the DB rather than a file on the local disk. In your function above, it runs this js on the client it then passes a BSON message to the server with the code of your pipeline in, no Javascript running on the server. Nothing wrong with that but a bit archaic .

Once - people would call these functions from mapReduce (Deprecated in 2013) or $where (Effectively deprecated about 2016) but most people 100% disable the javascript interpreter in the server anyway.

1 Like