Search in sources :

Example 86 with DBCursor

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;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor) HashMap(java.util.HashMap) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject)

Example 87 with DBCursor

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");
    }
}
Also used : DBCollection(com.mongodb.DBCollection) DBCursor(com.mongodb.DBCursor)

Aggregations

DBCursor (com.mongodb.DBCursor)87 BasicDBObject (com.mongodb.BasicDBObject)70 DBObject (com.mongodb.DBObject)54 DBCollection (com.mongodb.DBCollection)42 ArrayList (java.util.ArrayList)20 JSONObject (org.json.JSONObject)15 MongoException (com.mongodb.MongoException)11 DB (com.mongodb.DB)10 Test (org.junit.Test)9 BasicDBList (com.mongodb.BasicDBList)8 HashMap (java.util.HashMap)8 FailedDBOperationException (edu.umass.cs.gnscommon.exceptions.server.FailedDBOperationException)6 JSONArray (org.json.JSONArray)5 MongoClient (com.mongodb.MongoClient)4 ObjectId (org.locationtech.geogig.api.ObjectId)4 Function (com.google.common.base.Function)3 Date (java.util.Date)3 Iterator (java.util.Iterator)3 ObjectId (org.bson.types.ObjectId)3 WorkItem (com.example.entities.WorkItem)2