Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda