Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Mongo JSInterpreter SyntaxError: unexpected token: keyword 'function'

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!