Skip to content

Commit c900d68

Browse files
committed
JAVA-1181: Calls to new createIndexes command now go through DBTCPConnector, ensuring that auth is checked first.
1 parent 1cfed02 commit c900d68

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/com/mongodb/DBCollectionImpl.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -334,21 +334,26 @@ private void addBulkWriteResultToCommandResult(final BulkWriteResult bulkWriteRe
334334

335335
public void createIndex(final DBObject keys, final DBObject options, DBEncoder encoder) {
336336
DBTCPConnector connector = db.getConnector();
337-
DBPort port = db.getConnector().getPrimaryPort();
337+
final DBPort port = db.getConnector().getPrimaryPort();
338338

339339
try {
340340
DBObject index = defaultOptions(keys);
341341
index.putAll(options);
342342
index.put("key", keys);
343343

344344
if (connector.getServerDescription(port.getAddress()).getVersion().compareTo(new ServerVersion(2, 6)) >= 0) {
345-
BasicDBObject createIndexes = new BasicDBObject("createIndexes", getName());
345+
final BasicDBObject createIndexes = new BasicDBObject("createIndexes", getName());
346346

347347
BasicDBList list = new BasicDBList();
348348
list.add(index);
349349
createIndexes.put("indexes", list);
350350

351-
CommandResult commandResult = port.runCommand(db, createIndexes);
351+
CommandResult commandResult = connector.doOperation(db, port, new DBPort.Operation<CommandResult>() {
352+
@Override
353+
public CommandResult execute() throws IOException {
354+
return port.runCommand(db, createIndexes);
355+
}
356+
});
352357
try {
353358
commandResult.throwOnError();
354359
} catch (CommandFailureException e) {
@@ -362,8 +367,6 @@ public void createIndex(final DBObject keys, final DBObject options, DBEncoder e
362367
db.doGetCollection("system.indexes").insertWithWriteProtocol(asList(index), WriteConcern.SAFE,
363368
DefaultDBEncoder.FACTORY.create(), port, false);
364369
}
365-
} catch (IOException e) {
366-
throw new MongoException.Network("Operation on server " + port.getAddress() + " failed", e);
367370
} finally {
368371
connector.releasePort(port);
369372
}

0 commit comments

Comments
 (0)