W: majority and w: 0 for same database

Hi Everyone, in my project by default (on MongoClient level) the write concern is set to ‘majority’.
In one collection I am inserting geoposition from IoT devices and want to set w=0.
Ex.: my_coll = dbname.coll.with_options(wite_concern=WriteConcern(w=0))
After doing this whole my project falls down, there aren’t any responses from other write/update requests… some strange things happen)).
Note: my project build on twisted framework and to avoid blocking calls I defer all db operations to thread (I prefer pymongo driver to txmongo. The last one is not up to date and very poor documented).
Any recommendations or documentation will be helpful.
Also in the course M220P (where used flask module) how managed to not block code while database operations performing?

It is the desired behaviour, if you set w:0, then there will be no acknowledgments from the server.
https://docs.mongodb.com/manual/reference/write-concern/#writeconcern.

Do you mean to ask about the locking of database?
If yes, these links will help answer your queries:

https://docs.mongodb.com/manual/faq/concurrency/

https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/

Kanika

Hi @Kanika, thank You for reply.

  1. if for one collection I set w: 0, why queries from other collections in same database does not acknowledge? They have option majority.

  2. No, not locking database. I mean locking of execution my Python code (sockets reactor loop). It is needed to be a non-locking.

According to this api documentation, you can change the write/read concern, but that will be set only for an instance, which is my_coll in your case. So, I agree rest of your operations which does not involve this instance should work on default write concern.

You can check in replica set level using rs.conf() and check getLastErrorDefaults key value to know what was the write concern for the last error.

Check this link: https://docs.python.org/3/library/asyncio.html. It might help with async code that you are looking for.

Kanika

Thanks, I have found exactly what is happen:

when I do any insert or update with w=0, then find method will works with all read preferences EXCEPT primary and primaryPreffered. If I try to read from primary node it hangs forever. What I do wrong?

Hi @Hrachya_81527,

Its very hard to pin point the issue without looking at the whole project which is out of M220P scope :smiley:

I would recommend using community forums or taking help from technical services like Solutions Architect who will pay detailed attention to your project.

Kanika