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

219
Vistas
How does addToSet determine a duplicate?

Say I have a document that contains an array named Months. Each element in the array has a int field indicating which month & year it refers to (yyyyMM), e.g. 201612, 201701, etc.

Each such element also contains additional fields, pertaining to that particular month. e.g. int numOfItems, string Country, etc.

Now, assuming I have such document with only 2 elements in the array:

Months[0].month == 201612
Months[1].month == 201701

Then, I call addToSet with Months[1].month == 201701.

How does addToSet determine whether this is a duplicate or not?

Does it inspect and compare all sub-elements of Months[1] to do that? Does it only inspect the index of the element in the Months array?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This is directly from MongoDB.

MongoDB - AddToSet

If the value is a document, MongoDB determines that the document is a duplicate if an existing document in the array matches the to-be-added document exactly; i.e. the existing document has the exact same fields and values and the fields are in the same order. As such, field order matters and you cannot specify that MongoDB compare only a subset of the fields in the document to determine whether the document is a duplicate of an existing array element.

over 4 years ago · Santiago Trujillo 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