C # mongodb driver write concern

My web service is being written to mongodb, and I notice that the recordings fail a lot when loading. Reading this documentation I see that the default settings are set to "Confirmation" and they are reading this post. It seems I need to set it to a higher setting (safe mode - which seems to be outdated). So my question is: how do I initialize my mongodb so that my web service "always" writes to db (or throws an error) and does not fail (assuming it can write :))

From what I understand, I need to fix the “write problem”, but it’s not clear how to set it to “Ensure success in writing to db”

The code I'm using now to get Db:

MongoClient client = new MongoClient(connection_string); var server = client.GetServer(); Database = _db = server.GetDatabase(dbname); 
-1
source share
1 answer

For this connection string, there should be an option w = 1, which is used by default in later versions of the driver. In the connection string, it looks like this:

 mongodb://localhost/?w=1 

But this is the default value.

You write that “records fail” - how do you see it? For documents not in the database, or by getting errors? Let me know and I will update the answer.

0
source

Source: https://habr.com/ru/post/977504/


All Articles