File tree Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Expand file tree Collapse file tree 1 file changed +3
-2
lines changed Original file line number Diff line number Diff line change @@ -410,14 +410,15 @@ public void ensureIndex( DBObject keys , String name )
410
410
/**
411
411
* Ensures an index on this collection (that is, the index will be created if it does not exist).
412
412
* @param keys fields to use for index
413
- * @param name an identifier for the index
413
+ * @param name an identifier for the index. If null or empty, the default name will be used.
414
414
* @param unique if the index should be unique
415
415
* @throws MongoException
416
416
*/
417
417
public void ensureIndex ( DBObject keys , String name , boolean unique )
418
418
throws MongoException {
419
419
DBObject options = defaultOptions ( keys );
420
- options .put ( "name" , name );
420
+ if (name != null && !name .isEmpty ())
421
+ options .put ( "name" , name );
421
422
if ( unique )
422
423
options .put ( "unique" , Boolean .TRUE );
423
424
ensureIndex ( keys , options );
You can’t perform that action at this time.
0 commit comments