Last active
February 6, 2024 07:48
-
-
Save FONQRI/c8c57281a24ef590729d26a9edbb7f62 to your computer and use it in GitHub Desktop.
how to create custom function and use them in mongodb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// use admin database | |
use admin | |
// create function | |
db.system.js.save( | |
{ | |
_id: "testEchoFunc", | |
value : function(x) { return x; } | |
} | |
) | |
// load functions | |
db.loadServerScripts(); | |
// run function | |
db.runCommand( { | |
eval: function(){return testEchoFunc(65)} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment