Skip to content

Commit ded790a

Browse files
committed
JAVA-1970: In DB.createCollection method, defer collection creation if options is null, as per documentation
1 parent 3231890 commit ded790a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

driver/src/main/com/mongodb/DB.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ public String apply(final DBObject result) {
251251
* @mongodb.driver.manual reference/method/db.createCollection/ createCollection()
252252
*/
253253
public DBCollection createCollection(final String collectionName, final DBObject options) {
254-
executor.execute(getCreateCollectionOperation(collectionName, options));
254+
if (options != null) {
255+
executor.execute(getCreateCollectionOperation(collectionName, options));
256+
}
255257
return getCollection(collectionName);
256258
}
257259

driver/src/test/functional/com/mongodb/DBTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ public void shouldReceiveAnErrorIfCreatingCappedCollectionWithoutSize() {
117117
database.createCollection("someName", new BasicDBObject("capped", true));
118118
}
119119

120+
@Test
121+
public void shouldDeferCollectionCreationIfOptionsIsNull() {
122+
collection.drop();
123+
database.createCollection(collectionName, null);
124+
assertFalse(database.getCollectionNames().contains(collectionName));
125+
}
126+
120127
@Test
121128
public void shouldCreateCappedCollection() {
122129
collection.drop();

0 commit comments

Comments
 (0)