File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed
Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ public class MongoURI {
126126 public static final String MONGODB_PREFIX = "mongodb://" ;
127127
128128 private final MongoClientURI mongoClientURI ;
129+ private final MongoOptions mongoOptions ;
129130
130131 /**
131132 * Creates a MongoURI from a string.
@@ -134,10 +135,12 @@ public class MongoURI {
134135 */
135136 public MongoURI ( String uri ) {
136137 this .mongoClientURI = new MongoClientURI (uri , new MongoClientOptions .Builder ().legacyDefaults ());
138+ mongoOptions = new MongoOptions (mongoClientURI .getOptions ());
137139 }
138140
139141 public MongoURI (final MongoClientURI mongoClientURI ) {
140142 this .mongoClientURI = mongoClientURI ;
143+ mongoOptions = new MongoOptions (mongoClientURI .getOptions ());
141144 }
142145
143146 // ---------------------------------
@@ -183,11 +186,12 @@ public String getCollection(){
183186 }
184187
185188 /**
186- * Gets the options
187- * @return
189+ * Gets the options. This method will return the same instance of {@code MongoOptions} for every call, so it's
190+ * possible to mutate the returned instance to change the defaults.
191+ * @return the mongo options
188192 */
189193 public MongoOptions getOptions (){
190- return new MongoOptions ( mongoClientURI . getOptions ()) ;
194+ return mongoOptions ;
191195 }
192196
193197 /**
Original file line number Diff line number Diff line change @@ -66,4 +66,10 @@ public void testOptionDefaults() {
6666 assertEquals (options .slaveOk , false );
6767 assertEquals (options .isCursorFinalizerEnabled (), true );
6868 }
69+
70+ @ Test
71+ public void testOptionSameInstance () {
72+ MongoURI mongoURI = new MongoURI ( "mongodb://localhost" );
73+ assertSame (mongoURI .getOptions (), mongoURI .getOptions ());
74+ }
6975}
You can’t perform that action at this time.
0 commit comments