Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
Retrieving an array of Documents from mongoDB with Java

I have a collection containing documents of employees. Each employee have an array of documents with the projects this employee is currently involved in. The problem is that i don't know how to get/query the array of projects?

Here is an example of such document.

{name : "employe name" , age : "..employe age" , phoneNr : 12334 , projects : 
[{ projectName : "project name" , projectLeder : "project leader" }] }

Here is an example code for retrieving the values in the document except the project array.

public void printEmployees() {

    MongoCursor<Document> cursor = coll.find().iterator();

        while(cursor.hasNext()) {

            Document documentEmployee = cursor.next();
            System.out.println((String) documentEmployee.get("name"));
            System.out.println((Integer) documentEmployee.get("age"));
            System.out.println((Integer) documentEmployee.get("phoneNr"));
            //How do i query/extract the project array?

        }  

  }    
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can try something like this.

 while(cursor.hasNext()) { Document documentEmployee = cursor.next(); System.out.println(documentEmployee.getString("name")); System.out.println(documentEmployee.getInteger("age")); System.out.println(documentEmployee.getInteger("phoneNr")); }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda