简体   繁体   中英

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:

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

The specific JavaScript I am trying to run looks like:

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. Try this

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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