@@ -54,7 +54,6 @@ public class MongoConnectionStringBuilder : DbConnectionStringBuilder
54
54
{ "readpreference" , "readPreference" } ,
55
55
{ "readpreferencetags" , "readPreferenceTags" } ,
56
56
{ "replicaset" , "replicaSet" } ,
57
- { "safe" , "safe" } ,
58
57
{ "secondaryacceptablelatency" , "secondaryAcceptableLatency" } ,
59
58
{ "secondaryacceptablelatencyms" , "secondaryAcceptableLatency" } ,
60
59
{ "server" , "server" } ,
@@ -91,7 +90,6 @@ public class MongoConnectionStringBuilder : DbConnectionStringBuilder
91
90
private string _password ;
92
91
private ReadPreference _readPreference ;
93
92
private string _replicaSetName ;
94
- private bool ? _safe ;
95
93
private TimeSpan _secondaryAcceptableLatency ;
96
94
private IEnumerable < MongoServerAddress > _servers ;
97
95
private bool ? _slaveOk ;
@@ -376,27 +374,6 @@ public string ReplicaSetName
376
374
}
377
375
}
378
376
379
- /// <summary>
380
- /// Gets or sets the safe value.
381
- /// </summary>
382
- [ Obsolete ( "Use W=0 or W=1 instead." ) ]
383
- public bool ? Safe
384
- {
385
- get { return _safe ; }
386
- set
387
- {
388
- if ( value != null )
389
- {
390
- if ( ! value . Value && AnyWriteConcernSettingsAreSet ( ) )
391
- {
392
- throw new InvalidOperationException ( "Safe cannot be set to false if any other write concern values have been set." ) ;
393
- }
394
- }
395
- _safe = value ;
396
- base [ "safe" ] = ( value == null ) ? null : XmlConvert . ToString ( value . Value ) ;
397
- }
398
- }
399
-
400
377
/// <summary>
401
378
/// Gets or sets the SafeMode to use.
402
379
/// </summary>
@@ -405,7 +382,7 @@ public SafeMode SafeMode
405
382
{
406
383
get
407
384
{
408
- if ( _safe != null || AnyWriteConcernSettingsAreSet ( ) )
385
+ if ( AnyWriteConcernSettingsAreSet ( ) )
409
386
{
410
387
#pragma warning disable 618
411
388
return new SafeMode ( GetWriteConcern ( false ) ) ;
@@ -418,23 +395,20 @@ public SafeMode SafeMode
418
395
}
419
396
set
420
397
{
421
- Safe = null ;
422
- FSync = null ;
423
- Journal = null ;
424
- W = null ;
425
- WTimeout = null ;
426
-
427
- if ( value != null )
398
+ if ( value == null )
428
399
{
429
- Safe = value . Enabled ;
430
- if ( value . Enabled )
431
- {
432
- var writeConcern = value . WriteConcern ;
433
- if ( writeConcern . FSync != null ) { FSync = writeConcern . FSync . Value ; }
434
- if ( writeConcern . Journal != null ) { Journal = writeConcern . Journal . Value ; }
435
- if ( writeConcern . W != null ) { W = writeConcern . W ; }
436
- if ( writeConcern . WTimeout != null ) { WTimeout = writeConcern . WTimeout . Value ; }
437
- }
400
+ FSync = null ;
401
+ Journal = null ;
402
+ W = null ;
403
+ WTimeout = null ;
404
+ }
405
+ else
406
+ {
407
+ var writeConcern = value . WriteConcern ;
408
+ FSync = writeConcern . FSync ;
409
+ Journal = writeConcern . Journal ;
410
+ W = writeConcern . W ?? ( writeConcern . Enabled ? 1 : 0 ) ;
411
+ WTimeout = writeConcern . WTimeout ;
438
412
}
439
413
}
440
414
}
@@ -746,9 +720,27 @@ public override object this[string keyword]
746
720
ReplicaSetName = ( string ) value ;
747
721
break ;
748
722
case "safe" :
749
- #pragma warning disable 618
750
- Safe = Convert . ToBoolean ( value ) ;
751
- #pragma warning restore
723
+ var safe = Convert . ToBoolean ( value ) ;
724
+ if ( _w == null )
725
+ {
726
+ W = safe ? 1 : 0 ;
727
+ }
728
+ else
729
+ {
730
+ if ( safe )
731
+ {
732
+ // don't overwrite existing W value unless it's 0
733
+ var wCount = _w as WriteConcern . WCount ;
734
+ if ( wCount != null && wCount . Value == 0 )
735
+ {
736
+ W = 1 ;
737
+ }
738
+ }
739
+ else
740
+ {
741
+ W = 0 ;
742
+ }
743
+ }
752
744
break ;
753
745
case "secondaryacceptablelatency" :
754
746
case "secondaryacceptablelatencyms" :
@@ -838,7 +830,7 @@ public override bool ContainsKey(string keyword)
838
830
/// <returns>A WriteConcern.</returns>
839
831
public WriteConcern GetWriteConcern ( bool enabledDefault )
840
832
{
841
- return new WriteConcern ( _safe . HasValue ? _safe . Value : enabledDefault )
833
+ return new WriteConcern ( enabledDefault )
842
834
{
843
835
FSync = _fsync ,
844
836
Journal = _journal ,
@@ -945,7 +937,6 @@ private void ResetValues()
945
937
_password = null ;
946
938
_readPreference = null ;
947
939
_replicaSetName = null ;
948
- _safe = null ;
949
940
_secondaryAcceptableLatency = MongoDefaults . SecondaryAcceptableLatency ;
950
941
_servers = null ;
951
942
_slaveOk = null ;
0 commit comments