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

176
Vistas
Remove all elements in string array Mongoose schema

I'm trying to remove all of strings that match occurrences in the array of 'interestedStudents' in a Mongoose schema.

My Mongoose schema looks like this:

// Create a schema.
const schema = new mongoose.Schema<Post>({
    interestedStudents: {
        type: [{
            type: String,
            unique: true
        }],
        required: false,
    },
})

//Create model
export const PostModel = model<Post>('Post', schema);

I'm trying to remove by using:

await PostModel.updateMany({ interestedStudents: { $pullAll : [userId]}})

But I'm getting the following error:

"CastError: Cast to [string] failed for value "[ { '$pullAll': [ '62854109cf9a6db1fcf0393b' ] } ]" (type string) at path "interestedStudents.0" because of "CastError"\n at model.Query.exec

What am I doing wrong? Is my Schema set up wrong? Maybe it's not an array of string?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It was as easy as this for anyone else coming here:

const { modifiedCount } = await PostModel.updateMany({}, { $pull: { interestedStudents: userId } })
about 4 years ago · Juan Pablo Isaza Denunciar
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