简体   繁体   English

在 mongo shell 中运行 JavaScript 给出语法错误

[英]Run JavaScript in mongo shell gives syntax error

I am trying to run arbitray JavaScript from the mongo shell via 'load("myfile.js")' and it is giving me this error:我正在尝试通过'load(“myfile.js”)'从mongo shell 运行arbitray JavaScript,它给了我这个错误:

E  QUERY    [js] uncaught exception: SyntaxError: missing } after property list

The specific JavaScript I am trying to run looks like:我试图运行的特定 JavaScript 看起来像:

var cursor = db.movies.find({"year": "$not": { "$type": 16} });
while (cursor.hasNext()) {
    var x = cursor.next();

    /* replace invalid characters in x's strings ... */

    var p = parseInt(x.year.substring(0,4), 10)

    db.movies.update({_id : x._id}, p);
}

From the error is seems that something may need to be escaped but I am not sure what?从错误看来,有些东西可能需要转义,但我不确定是什么?

Your mongodb query seem to be missing a block.您的 mongodb 查询似乎缺少一个块。 Try this尝试这个

var cursor = db.movies.find({"year": { "$not": { "$type": 16 } } });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM