mongodb - 如何在 3.6.4 vs 2.4 Mongo 服务器 [system.js] 中执行 javascript 函数
问题描述
目前在 2.4 MongoDB 中。如果我们在 MongoDB Server 中创建函数,它可以通过以下方式很好地测试,但在 3.6.4 中会遇到错误
蒙哥 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
谁能指导我正确执行Mongo 3.6.4中的功能。
注意:它可以执行为
db.eval(getX, {})
,但不推荐使用。我需要正确的执行方式。
解决方案
推荐阅读
- excel - 没有隐式交集的 TEXTJOIN Excel 公式
- sql-server - 如何使用类型对象测试 SQL 过程
- vhdl - VHDL 中的并发和顺序语句
- python - 如果在 python 中花费超过 1 分钟,则使函数超时
- typescript - Fullcalendar v5 未出现在 JHipster 项目中
- c++ - setlocale() 不从 bindtextdomain() dir C++ 中读取
- c++ - 结构中的 C++ 私有变量在不使用 mutator func 的情况下被修改,不知道为什么?- OpenGL粒子系统
- excel - 使用 VBA 或手动对 MS excel 中的字母数字文本进行排序
- r - 从具有地理坐标 R 的轨迹创建归一化的成对矩阵
- laravel - 如何在一个查询中存储多个数组 laravel