Azure-docs: Duplicate key error

Created on 10 Apr 2018  Â·  15Comments  Â·  Source: MicrosoftDocs/azure-docs

Hey guys, after completing the full tutorial it seemed like everything was working great until I tried to add more than one hero to my database which continuously fails with the following error:

E11000 duplicate key error collection: admin.heros Failed _id or unique key constraint

I thought that maybe I had made a mistake in my code but after cloning the official react-cosmosdb repo and pointing it to my Cosmos DB instance I ran into the exact same failures. Any idea why this might be happening?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

assigned-to-author cosmos-dsvc doc-bug in-progress triaged

Most helpful comment

I believe this is a Mongoose issue. I have resolved it in the project by setting autoIncrement to false in the Mongoose Schema.

All 15 comments

The _id does appear different for the new hero I am adding so it's unclear why Cosmos DB is rejecting the add:
image

@ydogandjiev I believe the Mongo DB driver introduced some issues with this tutorial. It potentially has to do with version 2 versus version 3, as the React Cosmos DB project is using version 2. Let me reach out to the content owner. Thanks for bringing this to our attention.
Regards,
Mike

@burkeholland Another GitHub issue potentially related to the Mongo DB driver version issue as identified with GitHub #6905.

I believe this is a Mongoose issue. I have resolved it in the project by setting autoIncrement to false in the Mongoose Schema.

@burkeholland looks like you updated the code to address the issue, can we close this issue?

Yes. I've got confirmation that this has resolved the issue.

@ydogandjiev We will now proceed to close this thread. If there are further questions regarding this matter, please reopen it and we will gladly continue the discussion.

Thank you for the quick turnaround on this @burkeholland, @SnehaGunda, @Mike-Ubezzi-MSFT!

It turned out that I also needed to enable the following preview features on my CosmosDB instance in order to stop hitting the error:
image

@SnehaGunda, @Mike-Ubezzi-MSFT, it might be worth noting that in the documentation (if it isn't already).

@SnehaGunda Can you make this happen?

in-progress

I'm unable to connect at the moment with these settings and the new changes. I'm going to continue to look at this and try to figure out what has changed on my end.

Thanks @burkeholland. Feel free to take a look at my implementation of your tutorial here:
https://github.com/ydogandjiev/react-cosmosdb

I’ve taken it quite a bit past where your videos left off but the basics of how I connect to CosmosDB haven’t changed.

@ydogandjiev thank you for putting the sample together, @burkeholland will followup with you after he tests his sample with right versions. We are closing this issue for now, Feel free to reopen this issue or create a new one if you have any followup questions.

please-close

Was this page helpful?
0 / 5 - 0 ratings