Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!