Skip to content

Instantly share code, notes, and snippets.

@FONQRI
Last active February 6, 2024 07:48
Show Gist options
  • Save FONQRI/c8c57281a24ef590729d26a9edbb7f62 to your computer and use it in GitHub Desktop.
Save FONQRI/c8c57281a24ef590729d26a9edbb7f62 to your computer and use it in GitHub Desktop.
how to create custom function and use them in mongodb
// 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