Chapter 2: User management (Durable Writes)

I am trying to understand what needs to be done for the following task:

    _# TODO: Durable Writes_

_ # Use a more durable Write Concern for this operation._

My understanding that we should implement this using the following: write_concerns, however, remote server seems to be rejecting this command.

1 Like

What error message you get from the remote server?

It seems not to be possible to add a writeConcern in the insert_one command. See
Pymongo documentation

I get almost the same error on the status web page:
User Management: duplicate emails should not be allowed

I have passed it but creating an index manually…

1 Like

Try to add an index (email) into users document. It will fix the error


Ok, thanks for all your suggestion guys! I have tried creating an index that will make sure that the email is unique. Now the the test ‘test_no_duplicate_registrations’ is passing! However, first test ‘test_registration’ is failing, as it tries to insert a record that already exists :roll_eyes:. Maybe I have used an incorrect index?

EDIT: Managed to figure out the this issue. Apparently after querying database, there were a lot of duplicate user records created from me trying to complete previous tasks, so I had to revert my remote database back to it’s original state by running mongorestore --drop --gzip --uri mongodb+srv://m220student..., which resolved all issues mentioned above. :smile:

I have chose to put the email as the document’s _id. This way I did not have to create an index.

Exactly, I did re-restore the collections all the time when I think something wrong with database :grin:

Yeah, you can do that but existing docs was using ObjectId(random) as docs _id. I am not sure that it’s a good idea

Thanks, I missed that. It is noted now. I would like the mongodb team to comment on this issue.

Hi there,

A few comments about this thread:

This is not exactly true. The insert_one api does not provide an option to set the write concern object but you can do it at the collection level:

wc = WriteConcern(...)

This does not solve the initial comment! We are trying to specify durable write operations. Indexes are not particularly useful in that regard. I advise against creating indexes unless the lab/ticket instructs you to do so.

The error message that you are getting is not necessarily related with this ticket.
The data clean that you’ve done solves it but this is side effect of some other issue where you got unwanted data duplication.


1 Like

how you guys are creating index if I am trying from mongo shell I am getting below

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.users.createIndex({“email” : 1},{unique: true});
“numIndexesBefore” : 2,
“numIndexesAfter” : 2,
“note” : “all indexes already exist”,
“ok” : 1,
“operationTime” : Timestamp(1547960894, 1),
“$clusterTime” : {
“clusterTime” : Timestamp(1547960894, 1),
“signature” : {
“hash” : BinData(0,“bX6CDnZZsgA/MbVnAcTtcaJLAdw=”),
“keyId” : NumberLong(“6634407287454695425”)
NOTE : No index created before
and if I am trying from atlas Its create index but not unique index using below syntax

“email”: 1

not sure what syntax I need to put and where to put to create the index need help please

Please do not post the same question on 2 different threads.

See Error while executing user_management test

Hi @Norberto,

I don’t know what else I can do with Write Concern. It simply doesn’t work for me as I keep seeing duplicate emails after refreshing the collection:

wc = WriteConcern(w=“majority”)

What DID work for me is to create a unique index.

Can you help?


# TODO: Durable Writes
# Use a more durable Write Concern for this operation.

I use: WriteConcern with “majority” in insert_one

But, when run my test I have this error:

E pymongo.errors.ServerSelectionTimeoutError: your_testing_db_uri
(can be the same as atlas:27017: [Errno 11001] getaddrinfo failed, or a local mo
ngodb database):27017: [Errno 11001] getaddrinfo failed

If I enter by Atlas (website) it’s fine.

Can someone help me please?

@Edgar_43983, the error message you get is clear enough.

Your .ini file is wrong.

Thank you, the error was in .ini :+1: .