title: Want to create dynamic mongo query to accept the DTO fields
body: <p>I am creating a REST service using springboot and MONGO as database.
   I have a StudentDTO class with the following fields :</p>
  
  <pre><code>Class StudentDTO{
   @Id
   int s_no;
   String name;
   String dept;
   int dept_no;
   String course;
  
  //getter and setters 
  }
  </code></pre>
  
  <p>I have some criteria on which i need to fetch the data. These criteria may vary. Below are some example : 
  1. Can fetch data on name, dept
  2. Can fetch data on name, id
  3. May want data on name, dept and course. etc</p>
  
  <p>There is no fixed combination of criteria on which I can build my query.
  One of the solution which is not appropriate i try to write is : </p>
  
  <pre><code>Query query = new Query();
  
  Criteria criteria = new Criteria().andOperator(
  Criteria.where("id").is(Integer.parseInt(dto.getId()),
  Criteria.where("name").is(dto.getName()),
  Criteria.where("dept").exists(true).is(dto.getDept()),
  Criteria.where("dept_no").is(dto.getDept_no()),
  Criteria.where("course").is(dto.getSource()));
  
  query.addCriteria(criteria);
  List&lt;StudentDTO&gt; recordsList = mongoTemplate.find(query, StudentDTO.class, "student_collection");
  </code></pre>
  
  <p>In the above solution there is no accommodation for the scenario is any of the field is missing.
  To check weather attribute exist or not i tried using the below query :</p>
  
  <pre><code> Criteria.where("id").exist(true).is(Integer.parseInt(dto.getId());
  </code></pre>
  
  <p>but how i can add criteria over the DTO fields.</p>