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

163
Vistas
MongoDB showing 'Duplicate Key' error on updating JS Object using react, even though the entity is unique

The application contains various programs which have courses mapped to it. I'm trying to make modifications to the courses array using a drag and drop (dragging courses from 'Available Courses' to 'Mapped Courses' of a program).

'createProgram' function is called when an update request is made. It takes the initial values of the existingProgram, maps the new courses which come from a drap and drop component. Then passes the new object to the update route.

const createProgram = () => {
  
  newProgram = {
        _id: existingProgram._id,
        info: {
          name: existingProgram.name, // {required: true, unique: true, trim: true}
          overview: existingProgram.overview, // {default: null, trim: true}
          thumbnail: existingProgram.thumbnail, // {default: null, trim: true}
          subtitle: existingProgram.name
            .toLowerCase()
            .replace(/ /g, '-')
            .replace(/[^\w-]+/g, '')
            .replace(/-+/g, '-'), // {required: true, unique: true, trim: true}
    },
    // populating 'courses' array with pre-existing values then mapping the new courses
    // coming from 'Mapped Courses' column of react Drag & Drop
    courses: [
          ...existingCourses,
          columns['Mapped Courses'].items.map((course, index) => ({
            id: course.id,
            name: course.content,
            sequence: index,
          })),
    ],
  };

  axios
      .put('https://updateProgramAPI/')
      .then((response) => console.log(response))
      .catch((err) => console.log(err));
};

But MongoDB is showing the following error:

code: 11000,
codeName: 'DuplicateKey',
keyValue: { 'courses.sequence': 1 },
'$clusterTime': {
  clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1637694265 },
  signature: { hash: [Binary], keyId: [Long] }
}

The database isn't getting updated.

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