Skip to content

Commit

Permalink
Added slaveOk support to ConnectionString
Browse files Browse the repository at this point in the history
  • Loading branch information
rozza committed Oct 6, 2014
1 parent a90fdab commit edb6952
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions driver-core/src/main/com/mongodb/ConnectionString.java
Expand Up @@ -22,7 +22,6 @@
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -37,6 +36,7 @@
import static com.mongodb.AuthenticationMechanism.PLAIN;
import static com.mongodb.AuthenticationMechanism.SCRAM_SHA_1;
import static java.lang.String.format;
import static java.util.Arrays.asList;


/**
Expand Down Expand Up @@ -472,6 +472,10 @@ private Map<String, List<String>> parseOptions(final String optionsPart) {
if (optionsMap.containsKey("wtimeout") && !optionsMap.containsKey("wtimeoutms")) {
optionsMap.put("wtimeoutms", optionsMap.remove("wtimeout"));
}
// JAVA-1433 handle legacy slaveok settings
if (optionsMap.containsKey("slaveok") && !optionsMap.containsKey("readpreference")) {
optionsMap.put("readpreference", asList("secondaryPreferred"));
}

return optionsMap;
}
Expand Down Expand Up @@ -593,7 +597,7 @@ public String getURI() {
* @return the credentials
*/
public List<MongoCredential> getCredentialList() {
return credentials != null ? Arrays.asList(credentials) : new ArrayList<MongoCredential>();
return credentials != null ? asList(credentials) : new ArrayList<MongoCredential>();
}

/**
Expand Down
Expand Up @@ -188,6 +188,7 @@ class ConnectionStringSpecification extends Specification {
uri | readPreference
new ConnectionString('mongodb://localhost/' +
'?readPreference=secondaryPreferred') | secondaryPreferred()
new ConnectionString('mongodb://localhost/?slaveOk=true') | secondaryPreferred()
new ConnectionString('mongodb://localhost/' +
'?readPreference=secondaryPreferred' +
'&readPreferenceTags=dc:ny,rack:1' +
Expand Down

0 comments on commit edb6952

Please sign in to comment.