• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

151
Vistas
Mongodb upsert into embedded array

Here is my document schema:

  var UserSchema = new mongoose.Schema({
      username: {type: String, lowercase: true, unique: true},
      email: {type:String, unique: true},
      currentSquads: [{seriesId: String, squad: [String]}]
});

Given a _id(for the UserSchema document), seriesId and squad: I would like to update the user document with the new squad if the seriesId already exists in the currentSquads array, otherwise add a new object in the currentSquad array.

What is the best way to do this in Mongoose?

about 3 years ago · Santiago Trujillo
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 Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda