MongoDB has a write mechanism of fire and forget
. But does this guarantee that my writes will be written to disk eventually? So if i have a statement like this(in pymongo)
collection.insert(doc) #not passing safe=True
I understand that my write in above statement will not immediately reach the disk but is there a guarantee that it would ever reach the disk(maybe the next day or a week later) or can it get lost and never come back. My application needs dont want the writes to be done synchronously but they want the writes to happen even if its hours later.
AFAIK Fire and Forget has no guarantees - if you need them then use safe [that's what it is there for!]
See How safe is MongoDB's safe mode on inserts?
The meaning of "fire and forget" (aka the default writes of MongoDB) is that the driver will not confirm the write with the server. Your write is placed on the network, the driver confirms it reaches the network transport but past that no other checking is performed.
As long as the server & network is up, it is expected the write will succeed. However, this also means you won't find out about issues such as violating a unique index.
Writes initially occur in memory, and are flushed to disk at least every 60 seconds. If you have journalling turned on, the write will get into the journal within 100 ms – this journal can recover in case of a crash upon mongod restarting.
If you want to verify that a write has made it to mongod and successfully been applied in memory, you should set safe=True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With