|
3 | 3 | import com.google.code.morphia.Datastore;
|
4 | 4 | import com.google.code.morphia.DatastoreImpl;
|
5 | 5 | import com.google.code.morphia.Morphia;
|
6 |
| -import com.mongodb.DB; |
7 |
| -import com.mongodb.DBCollection; |
8 |
| -import com.mongodb.Mongo; |
9 |
| -import com.mongodb.ServerAddress; |
| 6 | +import com.mongodb.*; |
10 | 7 | import groovy.util.ConfigObject;
|
11 | 8 | import org.apache.commons.logging.Log;
|
12 | 9 | import org.apache.commons.logging.LogFactory;
|
@@ -50,18 +47,26 @@ public MongoHolderBean(GrailsApplication application) throws UnknownHostExceptio
|
50 | 47 | replicaSets = (List<String>)((ConfigObject)application.getConfig().get("mongodb")).get("replicaSet");
|
51 | 48 | } catch (Exception ignore) {}
|
52 | 49 |
|
| 50 | + MongoOptions mongoOptions = null; |
| 51 | + try { |
| 52 | + mongoOptions = (MongoOptions)((ConfigObject)application.getConfig().get("mongodb")).get("options"); |
| 53 | + } catch (Exception ignore) { } |
| 54 | + if (mongoOptions == null) mongoOptions = new MongoOptions(); |
| 55 | + |
53 | 56 | if (replicaSets != null) { // user replica sets
|
54 | 57 | log.info("Creating MongoDB connection with replica sets " + replicaSets + " and database " + database);
|
55 | 58 | List<ServerAddress> addressList = new ArrayList<ServerAddress>();
|
56 | 59 | for (String addr : replicaSets) {
|
57 | 60 | addressList.add(new ServerAddress(addr));
|
58 | 61 | }
|
59 |
| - mongo = new Mongo(addressList); |
| 62 | + |
| 63 | + mongo = new Mongo(addressList, mongoOptions); |
60 | 64 | } else { // use host port
|
61 | 65 | String host = getConfigVar(flatConfig, "mongodb.host", "localhost");
|
62 | 66 | int port = parsePortFromConfig(getConfigVar(flatConfig, "mongodb.port", "27017"), 27017);
|
63 | 67 | log.info("Creating MongoDB connection to host " + host + ":" + port + " and database " + database);
|
64 |
| - mongo = new Mongo(host, port); |
| 68 | + |
| 69 | + mongo = new Mongo(new ServerAddress(host, port), mongoOptions); |
65 | 70 | }
|
66 | 71 |
|
67 | 72 | morphia = new Morphia();
|
|
0 commit comments