title: Problem to implement FindById to a return statement in java with MongoDB
body: <p>UPDATE: The return statement is still not working as expected to show single user detail by id in the <code>DAO</code>. I could only use for loop to iterate through the <code>_id</code> to match the <code>userId</code>, but when I click the <code>edit</code> button for the number of user will show all previous user Id in the console.</p>
  <p><a href="https://i.stack.imgur.com/JWmiF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JWmiF.png" alt="enter image description here" /></a></p>
  <p>Another problem is when I call this method in the Service class, the output is <code>null</code>. Still crave for the solution to help me get over it.</p>
  <pre><code>@Override
  public User get(Object userId) {
  
      User user = new User();
      
      FindIterable&lt;Document&gt; userTbl = database.getCollection(&quot;User&quot;).find();
  for (Document doc : userTbl) {          
  
      String id = doc.getObjectId(&quot;_id&quot;).toString();
  System.out.println(&quot;_id = &quot; + id);
  
          if (id.equals(userId)) {
              return user;
          }
      }
  
      return null;
  }
  </code></pre>
  <p>edit user in Service class</p>
  <pre><code>public void editUser() throws ServletException, IOException {
  
      Object userId = request.getParameter(&quot;id&quot;); // get query string from the jsp
  
  User user = userDAO.get(userId);
  
  
  System.out.println(&quot;User full name is? &quot; + user.getFullName());
  
  }
  </code></pre>