Example usage for com.mongodb.client MongoCursor next

List of usage examples for com.mongodb.client MongoCursor next

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor next.

Prototype

@Override
    TResult next();

Source Link

Usage

From source file:data.ProjectMember.java

License:Open Source License

public static ArrayList<ProjectMember> getMembersByProjectId(int projectId, DBManagerMongo manager)
        throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find(eq("project_id", projectId));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;//from ww  w  . j  a  v  a 2  s . c  o  m
}

From source file:data.ProjectMember.java

License:Open Source License

public static ArrayList<ProjectMember> getInvolvedProjects(String loginName, DBManagerMongo manager)
        throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find(and(eq("user_login_name", loginName), eq("role", "MEMBER")));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;/*from   w ww  . j  a  va2  s  .  c om*/
}

From source file:data.ProjectMember.java

License:Open Source License

public static ArrayList<ProjectMember> getOwnedProject(String loginName, DBManagerMongo manager)
        throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find(and(eq("user_login_name", loginName), eq("role", "LEADER")));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;//  ww w.  j  av a 2  s.  c  o m
}

From source file:data.ProjectMember.java

License:Open Source License

public static List<ProjectMember> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<ProjectMember> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_member");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractMember(cursor.next(), manager));

    return list;//from   w  ww . ja v a  2 s  . com
}

From source file:data.ProjectPhase.java

License:Open Source License

public static ProjectPhase getByPrimaryKey(int id, DBManagerMongo manager) throws Exception {
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find(eq("id", id));
    MongoCursor<Document> cursor = doc.iterator();
    if (!cursor.hasNext())
        throw new Exception("no such record");

    return extractPhase(cursor.next(), manager);
}

From source file:data.ProjectPhase.java

License:Open Source License

public static ArrayList<ProjectPhase> getByProjectId(int projectId, DBManagerMongo manager) throws Exception {
    ArrayList<ProjectPhase> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find(eq("project_id", projectId));
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractPhase(cursor.next(), manager));

    return list;/*from w  w  w . java 2  s . c om*/
}

From source file:data.ProjectPhase.java

License:Open Source License

public static List<ProjectPhase> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<ProjectPhase> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("project_phase");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractPhase(cursor.next(), manager));

    return list;//w ww. ja v a2 s .c o m
}

From source file:data.User.java

License:Open Source License

public static User getByPrimaryKey(String loginName, DBManagerMongo manager) throws Exception {
    MongoCollection<Document> coll = manager.getDb().getCollection("user");
    FindIterable<Document> doc = coll.find(eq("login_name", loginName));
    MongoCursor<Document> cursor = doc.iterator();
    if (!cursor.hasNext())
        throw new Exception("no such record");

    return extractUser(cursor.next());
}

From source file:data.User.java

License:Open Source License

public static List<User> getAll(DBManagerMongo manager) throws Exception {
    ArrayList<User> list = new ArrayList<>();
    MongoCollection<Document> coll = manager.getDb().getCollection("user");
    FindIterable<Document> doc = coll.find();
    MongoCursor<Document> cursor = doc.iterator();
    while (cursor.hasNext())
        list.add(extractUser(cursor.next()));

    return list;//from www.j  a v a2  s  .c o  m
}

From source file:de.jan.smartenergybackend.de.MongoDBClient.java

/**
 * /*from  w  w w  .j  a  va2  s  .c o  m*/
 * @param startTime
 * @param entTime
 * @return The avarage of the measured values in the given time slot
 */
public long getSmartMeterValueAvarage(int startTime, int entTime) {
    FindIterable<Document> findIt = collection.find();
    MongoCursor<Document> mongoCurser = findIt.iterator();
    int count = 0;
    long sum = 0;
    while (mongoCurser.hasNext()) {
        Document next = mongoCurser.next();
        sum += next.getLong("value");
        count++;
    }
    if (count > 0) {
        return sum / count;
    } else {
        return -1;
    }
}