Question:
So I have a simple collection with an additional index on one field called “reactionId”. I then want to bulk-upsert multiple documents to that collection. The first one gets inserted, and then I get the errorThis is the
Reaction
model:Answer:
The problem is that the index is defined on the property “reactionID” – notice the upper-case ID. In your model, the property is named “reactionId” with a lower-case d. Hence, when inserting, your document does not contain a value for the property that MongoDB expects. This leads to a null value for both documents in the index – hence the duplicate key violation.If you drop the index and redefine it for “reactionId”, this insert should work.
If you have better answer, please add a comment about this, thank you!