use of com.mongodb.DBCursor in project graylog2-server by Graylog2.
the class InputServiceImpl method totalCountByType.
@Override
public Map<String, Long> totalCountByType() {
final Map<String, Long> inputCountByType = new HashMap<>();
try (DBCursor inputTypes = dbCollection.find(null, new BasicDBObject(MessageInput.FIELD_TYPE, 1))) {
for (DBObject inputType : inputTypes) {
final String type = (String) inputType.get(MessageInput.FIELD_TYPE);
if (type != null) {
final Long oldValue = inputCountByType.get(type);
final Long newValue = (oldValue == null) ? 1 : oldValue + 1;
inputCountByType.put(type, newValue);
}
}
}
return inputCountByType;
}
use of com.mongodb.DBCursor in project nanopub-server by tkuhn.
the class PeerListPage method show.
public void show() throws IOException {
DBCollection coll = NanopubDb.get().getPeerCollection();
DBCursor cursor = coll.find();
int c = 0;
printStart();
while (cursor.hasNext()) {
c++;
printElement(cursor.next().get("_id").toString());
}
if (c == 0 && asHtml) {
println("<li><em>(no known peers)</em></li>");
}
printEnd();
if (asHtml) {
getResp().setContentType("text/html");
} else {
getResp().setContentType("text/plain");
}
}
Aggregations