Skip to content

Commit 34182eb

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

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
@@ -253,7 +253,9 @@ public String apply(final DBObject result) {
253253
* @mongodb.driver.manual reference/method/db.createCollection/ createCollection()
254254
*/
255255
public DBCollection createCollection(final String collectionName, final DBObject options) {
256-
executor.execute(getCreateCollectionOperation(collectionName, options));
256+
if (options != null) {
257+
executor.execute(getCreateCollectionOperation(collectionName, options));
258+
}
257259
return getCollection(collectionName);
258260
}
259261

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)