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

178
Vistas
convert $_id to string on the fly

I have the following update query, I want to use the value of the _id field. However, I can't, because _id is an ObjectId. and the field that I am writing on requires a string.

How to convert the _id to a string on the fly, within the request, in the concat function?

{ $concat: [`email`, ' #deleted(','$_id', ')'] }
  • I am using MongoDB in Mongoose In JavaScript.

full code if required:

await Model.findOneAndUpdate(req.params.id, [
    {
      $set: {
        email: {
          $concat: ['$email', ' #deleted(', '$_id', ')'],
        },
        _archived: Date.now(),
      },
    },
  ])

currently getting:

MongoServerError: Plan executor error during findAndModify :: caused by :: $concat only supports strings, not objectId

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