Example usage for com.mongodb.client MongoCollection find

List of usage examples for com.mongodb.client MongoCollection find

Introduction

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

Prototype

FindIterable<TDocument> find(ClientSession clientSession);

Source Link

Document

Finds all documents in the collection.

Usage

From source file:dto.Dto.java

public String listarTesisSinAsesor(String seccion) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    MongoCursor<Document> cursor = col.find(and(eq("seccion", (seccion)), eq("idAsesor", "0"))).iterator();
    Document doc;/*from   w  w  w  .j av  a 2s .c  om*/
    String cadena = "";
    try {

        while (cursor.hasNext()) {
            doc = cursor.next();
            cadena += "<tr>" + "<td width='20%'>" + doc.getString("titulo").toUpperCase().trim() + "</td>"
                    + "<td width='20%'><select id='sel' style='display:inline'><option>*** Seleccione asesor ***</option></select></td>"
                    + "<td><button onclick='enviarSolicitud(" + doc.getString("_id")
                    + ")'>Enviar</button></td></tr>";
            //System.out.println(doc);               
        }
        //p = doc.getString("nombre");
    } catch (NullPointerException e) {
        System.out.println("listar sin asesor: " + e);
    } finally {
        cursor.close();
    }
    return cadena;
}

From source file:dto.Dto.java

public void aceptarTesisProfesor(String idTesis) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    Document doc = col.find(eq("_id", idTesis)).first();

    col.updateOne(doc, new Document("$set", new Document("estadoP", "aceptado")));
}

From source file:dto.Dto.java

public void rechazarTesisProfesor(String idTesis) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    Document doc = col.find(eq("_id", idTesis)).first();

    col.updateOne(doc, new Document("$set", new Document("estadoP", "rechazado")));
}

From source file:dto.Dto.java

public void aceptarSolicitudAsesor(String idTesis, String idAsesor) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    Document doc = col.find(eq("_id", idTesis)).first();

    col.updateOne(doc, new Document("$set", new Document("estadoA", "aceptado")));

    MongoCollection<Document> col1 = c.getConnection("tesis_alumno_asesor");
    Document doc2 = col1.find(eq("_id", idTesis)).first();

    col.updateOne(doc2, new Document("$set", new Document("idAsesor", idAsesor)));
}

From source file:dto.Dto.java

public void rechazarSolicitudAsesor(String idTesis) {
    MongoCollection<Document> col = c.getConnection("tesis_alumno_asesor");
    Document doc = col.find(eq("_id", idTesis)).first();
    col.updateOne(doc, new Document("$set", new Document("estadoA", "rechazado")));

    MongoCollection<Document> col1 = c.getConnection("tesis_alumno_asesor");
    Document doc2 = col1.find(eq("_id", idTesis)).first();
    col.updateOne(doc2, new Document("$set", new Document("idAsesor", 0)));
}

From source file:dto.Dto.java

public void aceptarActa(String idActa) {
    MongoCollection<Document> col = c.getConnection("actas");
    Document doc = col.find(eq("_id", idActa)).first();

    col.updateOne(doc, new Document("$set", new Document("estado", "aceptado")));
}

From source file:dto.Dto.java

public void rechazarActa(String idActa) {
    MongoCollection<Document> col = c.getConnection("actas");
    Document doc = col.find(eq("_id", idActa)).first();

    col.updateOne(doc, new Document("$set", new Document("estado", "rechazado")));
}

From source file:DutyDatabase.DutyScheduleDB.java

License:Open Source License

/**
 * Retrieved a previously stored scheduled calendar in the database.
 * @param id ID of the user./* w  w w  . j  ava2  s .c o  m*/
 * @param calendarName Name of the calendar to retrieve.
 * @return List of DutyBlocks comprising the calendar retrieved.
 */
public ArrayList<DutyBlock> getScheduledCalendar(String id, String calendarName) {
    MongoCollection col = db.getCollection("ScheduledCalendars");
    Document testDoc = (Document) col.find(new Document("name", id + calendarName)).first();
    //Access collection of scheduled calendars.
    MongoCollection<ScheduledDuty> collection = db.getCollection("ScheduledCalendars")
            .withDocumentClass(ScheduledDuty.class);
    //Search for specified calendar.
    ScheduledDuty doc = (ScheduledDuty) collection.find(new Document("name", id + calendarName)).first();
    return doc.getDutyCalendar();
}

From source file:es.dheraspi.sums.model.DAOMongoDB.java

@Override
public Map<String, String> getLanesSumsAnalysis(Summoner summoner) {
    Map<String, String> lanes_data = new HashMap<String, String>();
    MongoCredential credential = MongoCredential.createCredential(user, dbname, password.toCharArray());
    try (MongoClient mongoClient = new MongoClient(new ServerAddress(host), Arrays.asList(credential))) {
        db = mongoClient.getDatabase(dbname);
        MongoCollection<Document> coll = db.getCollection("analysis");

        Bson query = new Document("_id", Long.toString(summoner.getID()));
        FindIterable<Document> iterable = coll.find(query);

        try {/*from   w ww  . j av a  2s  .c o  m*/
            Document bot_doc = (Document) iterable.first().get("bot");
            Document mid_doc = (Document) iterable.first().get("mid");
            Document jun_doc = (Document) iterable.first().get("jun");
            Document top_doc = (Document) iterable.first().get("top");

            Iterator<String> kiter = bot_doc.keySet().iterator();
            Iterator<Object> viter = bot_doc.values().iterator();
            String bot = "";
            try {
                bot = bot + "[{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                for (int i = 0; i < bot_doc.size() - 1; i++) {
                    bot = bot + ",{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                }
                bot = bot + "]";
            } catch (NoSuchElementException ex) {
            }

            kiter = mid_doc.keySet().iterator();
            viter = mid_doc.values().iterator();
            String mid = "";
            try {
                mid = mid + "[{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                for (int i = 0; i < mid_doc.size() - 1; i++) {
                    mid = mid + ",{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                }
                mid = mid + "]";
            } catch (NoSuchElementException ex) {
            }

            kiter = jun_doc.keySet().iterator();
            viter = jun_doc.values().iterator();
            String jun = "";
            try {
                jun = jun + "[{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                for (int i = 0; i < jun_doc.size() - 1; i++) {
                    jun = jun + ",{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                }
                jun = jun + "]";
            } catch (NoSuchElementException ex) {
            }

            kiter = top_doc.keySet().iterator();
            viter = top_doc.values().iterator();
            String top = "";
            try {
                top = top + "[{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                for (int i = 0; i < top_doc.size() - 1; i++) {
                    top = top + ",{\"summoners\": \"" + kiter.next() + "\", \"wins\": " + viter.next() + "}";
                }
                top = top + "]";
            } catch (NoSuchElementException ex) {
            }

            if (!bot.equals(""))
                lanes_data.put("bot", bot);
            if (!mid.equals(""))
                lanes_data.put("mid", mid);
            if (!jun.equals(""))
                lanes_data.put("jun", jun);
            if (!top.equals(""))
                lanes_data.put("top", top);
        } catch (NullPointerException ex) {
            // No games found
        }

        return lanes_data;
    }
}

From source file:es.dheraspi.sums.model.DAOMongoDB.java

@Override
public String getLanesChampsSums(Summoner summoner) {
    MongoCredential credential = MongoCredential.createCredential(user, dbname, password.toCharArray());
    try (MongoClient mongoClient = new MongoClient(new ServerAddress(host), Arrays.asList(credential))) {
        db = mongoClient.getDatabase(dbname);
        MongoCollection<Document> coll = db.getCollection("analysis");

        Bson query = new Document("_id", Long.toString(summoner.getID()));
        FindIterable<Document> iterable = coll.find(query);

        Document doc = iterable.iterator().next();
        Document result = (Document) doc.get("lane_champ_sums");

        return result.toJson();
    } catch (NoSuchElementException | NullPointerException ex) {
        return "empty";
    }/* www  .j  av a 2s.c o  m*/
}