Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!