Can someone explain me the difference between the default value of SetSafe()
which is &Safe{}
and SetSafe(nil)
?
As per the mgo godoc:
If the safe parameter is nil, the session is put in unsafe mode, and writes become fire-and-forget, without error checking. The unsafe mode is faster since operations won't hold on waiting for a confirmation.
If the safe parameter is not nil, any changing query (insert, update, ...) will be followed by a getLastError command with the specified parameters, to ensure the request was correctly processed.
The default is &Safe{}, meaning check for errors and use the default behavior for all fields.
Looking at the code it seems it will call getLastError
command in mongo with values j:false, w:0, wtimeout:0
. This means it will not return any error from mongo and the behavior seems to be similar while calling SetSafe(nil)
.
Then what error I am expected to receive while calling mongo with SetSafe(&Safe{})
?
I am on Mongo 3.0.9.