User already exists in tests

I have a bit of a problem. I’m doing both this course and the MongoDB fundamentals (because I was already studying mongoDB independently before) and I keep getting this Error when I run the tests.

Thank you for your answers.

1 Like

i have same problem.
trying to set up unique index on but failed due to existing duplicates

I believe that the tests leave behind the duplicate. So, remove those entries and create a partial index.

I have same problem. The method add_user in does not throw exception ‘DuplicateKeyError’.

Actually I don’t know about index . I review again the lesson video and do my own duplicate detection to pass lab.

I was thinking about that, but then you have to throw an exception yourself instead of letting the DB do it…

I had that problem too. I first tried to define a unique index on email in Compass but that failed because it said there were existing duplicates in the document with nulls. When I looked through the whole set of users in Compass there were indeed some documents at the end with ‘null’ values. I deleted them in Compass and tried to define the index again. This time I got a message saying that all required indexes already existed but the tests now passed. It was almost as though those rogue documents caused the unique index to be ignored.

Hope that helps - Cheers :smile:

i get thru the test by doing a find first and throw that duplicate error if the find succeed…
Ron’s solution is more ‘correct’ though.

I tried to filter if there are duplicate emails registered and if the input email to add in the collection is already in the collection. Still no result in the tests or in the execution of the web. I tried to remove those null documents in Compass and still doesn’t get to work. Any ideas or if my code is kind of ruining everything?
Thanks again community.