Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

371
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda