SetSafe Default Value in mgo session

25 views
Skip to first unread message

tuk

unread,
Aug 4, 2016, 7:07:37 AM8/4/16
to mgo-users

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 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.

Debraj Manna

unread,
Aug 4, 2016, 11:33:15 PM8/4/16
to mgo-...@googlegroups.com

Can someone help me in clearing my doubts?


--
You received this message because you are subscribed to a topic in the Google Groups "mgo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mgo-users/DaFy2TCQhWc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mgo-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages