Currently in 2.4 MongoDB. If we create functions in MongoDB Server it can be tested well in the below way but facing error with 3.6.4
MONGO 2.4
$mongo emgda
>db.system.js.save({
... "_id" : "getX",
... "value" : "function(obj) { return 'Hey I got Executed.' }"
... });
>
>db.loadServerScripts()
>getX({})
Hey I got Executed.
MONGO 3.6.4
$mongo emgda
>db.system.js.save({
... "_id" : "getX",
... "value" : "function(obj) { return 'Hey I got Executed.' }"
... });
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
>
>db.loadServerScripts()
>getX({})
2019-10-03T13:35:22.583+0530 E QUERY [thread1] TypeError: getX is not a function :
@(shell):1:1
Can any one please guide me through the correct way of executing the function in Mongo 3.6.4.
NOTE: It can be executed as
db.eval(getX, {})
, but this is deprecated. I need the correct way of execution.