title: Add optional query parameter using spring data mongodb repository
body: <p>I want to add optional query parameters using spring data mongodb.</p>
  
  <p>Controller code:</p>
  
  <pre><code>@RestController
  private final ActionService actionService;
  
  
  @RequestMapping(value = "/action/{id}", method = RequestMethod.GET)
  public ResponseEntity&lt;List&lt;Action&gt;&gt; getActionList(@PathVariable("id") long id,
              @RequestParam(value = "actionType", required = false) ActionType actionType,
              @RequestParam(value = " ", required = false) String[] params) {
  
          List&lt;Action&gt; actionList = actionService.getAction(id, actionType, params);
          return new ResponseEntity&lt;&gt;(actionList, HttpStatus.OK);
  }
  </code></pre>
  
  <p>ActionServiceImpl.java</p>
  
  <pre><code>private ActionRepository actionRepository;
  
  public List&lt;Action&gt; getAction(long id, ActionType type, String... var1) {
      return actionRepository.getByActionType(id, type, var1.length &gt; 0 ? var1[0] : "", var1.length &gt; 1 ? var1[1] : "", var1.length &gt; 2 ? var1[2] : "");
  }
  </code></pre>
  
  <p>ActionRepository.java</p>
  
  <pre><code>@Repository
  public interface ActionRepository extends MongoRepository&lt;Action, String&gt; {
  
      @Query(value = "{ 'id' : ?0  , 'actionType' : ?1 ,  'param1' : ?2 , 'param2': ?3 , 'param3' : ?4 } ")
      List&lt;Action&gt; getByActionType(long id, ActionType type, String var1, String var2, String var3);
  }
  </code></pre>
  
  <p>Note: 'id' is mandatory field and action type and params are optional. I want to get data based on 'id' whether I pass action type/params or not. Currently, i am getting null pointer exception in 'ActionServiceImpl' as I am not passing params and action Type. 'Action Type' is enumeration. </p>
  
  <p>Can someone help me to change ActionRepository @Query tag so, that I can get data based on id without passing actionType or params. e.g. if I pass action type then mongo query should give result based on 'id $or actionType'.</p>