title: Spring data MongoDB condition in projection
body: <p>How can I add condition on my projection stage during aggregation using Spring Data?</p>
  
  <p>For example I want to add <code>new_field</code> that will be calculated by formula <code>field1 / field2</code>. From Code side it would look like:</p>
  
  <pre><code>ProjectionOperation projectionOperation = project("field1", "field2").andExpression("field1 / field2").as("field3");
  </code></pre>
  
  <p>But if <code>field2</code> is equal to <code>0</code>, I'll get an error. So to avoid such situation it was suggested to use <code>$cond</code> operator but I have no idea how it should look like in code. Do anybody have any thoughts?</p>
  
  <p>Note. Expression <code>field2 != 0 ? 1 : 0</code> didn't work (even if "SpEL" allows such syntax).</p>