Skip to content

Commit 2d91ec1

Browse files
committed
Removed support for non-cursor-based listCollections and listIndexes command results, which was removed in 2.8.0-rc4.
JAVA-1616
1 parent befb3cf commit 2d91ec1

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

src/main/com/mongodb/DBApiLayer.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -149,27 +149,19 @@ public Set<String> getCollectionNames() {
149149
try {
150150
List<String> collectionNames = new ArrayList<String>();
151151
if (isServerVersionAtLeast(asList(2, 7, 7))) {
152-
CommandResult res = command(new BasicDBObject("listCollections", getName()).append("cursor", new BasicDBObject()),
153-
ReadPreference.primary());
152+
CommandResult res = command(new BasicDBObject("listCollections", getName()), ReadPreference.primary());
154153
if (!res.ok() && res.getCode() != 26) {
155154
res.throwOnError();
156155
} else {
157-
List<DBObject> collections = (List<DBObject>) res.get("collections");
158-
if (collections != null) {
159-
for (DBObject collectionInfo : collections) {
156+
QueryResultIterator iterator = new QueryResultIterator(res, getMongo(), 0, DefaultDBDecoder.FACTORY.create(),
157+
res.getServerUsed());
158+
try {
159+
while (iterator.hasNext()) {
160+
DBObject collectionInfo = iterator.next();
160161
collectionNames.add(collectionInfo.get("name").toString());
161162
}
162-
} else {
163-
QueryResultIterator iterator = new QueryResultIterator(res, getMongo(), 0, DefaultDBDecoder.FACTORY.create(),
164-
res.getServerUsed());
165-
try {
166-
while (iterator.hasNext()) {
167-
DBObject collectionInfo = iterator.next();
168-
collectionNames.add(collectionInfo.get("name").toString());
169-
}
170-
} finally {
171-
iterator.close();
172-
}
163+
} finally {
164+
iterator.close();
173165
}
174166
}
175167
} else {

src/main/com/mongodb/DBCollectionImpl.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,21 @@ public List<DBObject> getIndexInfo() {
343343
List<DBObject> list = new ArrayList<DBObject>();
344344

345345
if (db.isServerVersionAtLeast(asList(2, 7, 6))) {
346-
CommandResult res = _db.command(new BasicDBObject("listIndexes", getName()).append("cursor", new BasicDBObject()),
347-
ReadPreference.primary());
346+
CommandResult res = _db.command(new BasicDBObject("listIndexes", getName()), ReadPreference.primary());
348347
if (!res.ok() && res.getCode() == 26) {
349348
return list;
350349
}
351350
res.throwOnError();
352-
List<DBObject> indexes = (List<DBObject>) res.get("indexes");
353-
if (indexes != null) {
354-
for (DBObject indexDocument : indexes) {
355-
list.add(indexDocument);
356-
}
357-
} else {
358-
QueryResultIterator iterator = new QueryResultIterator(res, db.getMongo(), 0, DefaultDBDecoder.FACTORY.create(),
359-
res.getServerUsed());
360-
try {
361-
while (iterator.hasNext()) {
362-
DBObject collectionInfo = iterator.next();
363-
list.add(collectionInfo);
364-
}
365-
} finally {
366-
iterator.close();
351+
352+
QueryResultIterator iterator = new QueryResultIterator(res, db.getMongo(), 0, DefaultDBDecoder.FACTORY.create(),
353+
res.getServerUsed());
354+
try {
355+
while (iterator.hasNext()) {
356+
DBObject collectionInfo = iterator.next();
357+
list.add(collectionInfo);
367358
}
359+
} finally {
360+
iterator.close();
368361
}
369362
} else {
370363
BasicDBObject cmd = new BasicDBObject("ns", getFullName());

0 commit comments

Comments
 (0)