mongo jsinterpreter syntaxerror:意外令牌:关键字' function'
我正在使用mongodb 4.4.8,根据,$ function
是4.4中的新事物,但是运行以下代码,服务器响应:
在我的配置文件中,security.javascriptenabled
,所以我认为应该它默认为true
命令失败,错误139(JSInterPreterFailure):'SyntaxError:意外令牌:preateword'function'''{}}。完整的响应是{“ ok”:0.0,“ errmsg”:“ syntaxerror:意外令牌:关键字'函数'“”,“ code”:139,“ codeName”:“ jsinterpreterfailure”}
db.my_collection.aggregate(
[
{$addFields:{
query: {
$function:{
body: function(ss){
arr = ss.split('|');
result = {};
arr.forEach(element => {
kv = element.split(':');
result[kv[0]] = kv[1];
});
return result['q']},
args: ['my_field'],
lang:'js'
}
}
}}
]);
函数可以在我的计算机上成功执行,但是Mongo似乎无法解析关键字函数
,发生了什么?
I am using MongoDB 4.4.8, according to mongo reference, $function
is new in 4.4, but running the following code, the server responded:
In my config file, security.javascriptEnabled
is not set, so I think it should be default to true
Command failed with error 139 (JSInterpreterFailure): 'SyntaxError: unexpected token: keyword 'function'' on server {}. The full response is {"ok": 0.0, "errmsg": "SyntaxError: unexpected token: keyword 'function'", "code": 139, "codeName": "JSInterpreterFailure"}
db.my_collection.aggregate(
[
{$addFields:{
query: {
$function:{
body: function(ss){
arr = ss.split('|');
result = {};
arr.forEach(element => {
kv = element.split(':');
result[kv[0]] = kv[1];
});
return result['q']},
args: ['my_field'],
lang:'js'
}
}
}}
]);
The function can be executed successfully on my computer, but mongo seemed not be able to parse the keyword function
, what happened?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题,但是我直接在Mongo Shell中尝试了,并且它起作用了,这可能是Datagrip的问题,而不是Mongo令人惊讶。至于为什么?我不知道。
因此,尝试在控制台中尝试相同的聚合
I had the same problem but I tried in the mongo shell directly and it worked, might be a problem with DataGrip rather than with mongo surprisingly. As to why? I don't know.
So try the same aggregation in the console instead