Ticket: User Management - (Add_User)

I am getting the following duplicate error on “Add_User” function in db.py…
I have tried both of the following lines of code… what am I doing wrong???

db.users.insert_one({“name”: name,“email”: email,“password”: hashedpw})

db.users.update_one({“email”: email},{"$set": {“name”: name,“email”: email,“password”: hashedpw}}, upsert=True)

_______________________ test_no_duplicate_registrations _______________________

client = <FlaskClient <Flask ‘mflix.factory’>>

@pytest.mark.user_management
def test_no_duplicate_registrations(client):
    result = add_user(test_user.get('name'), test_user.get(
        'email'), test_user.get('password'))
  assert result == {'error': "A user with the given email already exists."}

E AssertionError: assert {‘success’: True} == {‘error’: ‘A user wi…ail already exists.’}
E Left contains more items:
E {‘success’: True}
E Right contains more items:
E {‘error’: ‘A user with the given email already exists.’}
E Use -v to get the full diff

tests\test_user_management.py:37: AssertionError
============================= 39 tests deselected =============================
============== 1 failed, 3 passed, 39 deselected in 4.32 seconds ==============

having same issue. haven’t found a fix yet

Found answer here:
https://discourse.university.mongodb.com/t/ticket-user-management-duplicate-email-error/6518/21?u=coryellcp

eliminate the duplicates email and creating a unique index
it work for me
thanks

Same isssue, do we need to user WriteConcern to make email as id field ?

it seems there are multiple records of the same email id and several emails as null:

db.users.aggregate([{$group:{_id:"$email",EmailCount:{$sum:1}}},{$match:{EmailCount:{$gt:1}}},{$sort:{EmailCount:-1}}])

hey,
i am also getting the same error can you help me in removing that.