title: Need to fetch a list of customer's customerID having same first_name from mongoDB Atlas from a java application using java 3.12.0 driver
body: <p>By using the following code i am able to get the list of customer objects having same first_name, but for my next operation i only need the <code>customerID</code>s of all the fetched customers, instead i am only getting the first fetched <code>customerID</code> for all objects. can anyone please help?</p>
  
  <pre><code>MongoClientURI uri = new MongoClientURI("mongodb+srv://sumitraojha:&lt;pwd&gt;@cluster0-tkx83.mongodb.net/customer?retryWrites=true&amp;w=majority");
  MongoClient mongoClient = new MongoClient(uri);
  System.out.println("The connection to mongoDB is established");
  
  //MongoDB Customer Database connection
  MongoDatabase cust_database = mongoClient.getDatabase("customer");
  System.out.println("The connection to Database\t"+cust_database.getName()+"\tis established successfully");
  //System.out.println("the database is "+cust_database.getName());
  
  //Displaying the Queried Document
  System.out.println("\n Enter the customer Name to search:\n ");
  Scanner sc = new Scanner(System.in);
  String fname = sc.next();
  System.out.println("\n The Customer Details are:");
  MongoCollection&lt;Document&gt; newcustDetails = cust_database.getCollection("NewCustomerDetails");
  
  MongoCursor&lt;Document&gt; custcursor1 = newcustDetails.find(eq("first_name", fname)).iterator(); 
  //System.out.println(custcursor1); 
  ArrayList&lt;String&gt; value = new ArrayList&lt;String&gt;();
  try { 
      while(custcursor1.hasNext()) 
      { 
  
      System.out.println("\n"+custcursor1.next().toJson());
      String temp = newcustDetails.find().projection(Projections.include("CustomerID")).first().getString("CustomerID");
      System.out.println(temp);
      value.add(temp);
      } 
  
      } 
      finally { 
                // TODO: handle finally clause
                custcursor1.close(); 
                }
  System.out.println("\n The Customer ID are:\t\t");
      Iterator&lt;String&gt; i1=value.iterator();  
      while(i1.hasNext())  
      {  
          System.out.println(i1.next());  
      }  
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dNlXd.png" rel="nofollow noreferrer">this is the output i am getting</a></p>