title: Call function inside mongodb's aggregate?
body: <p>Collection:</p>
  
  <pre><code>[
      { _id: "Foo", flag1: false, flag2: true, flag3: false },
      { _id: "Bar", flag1: true, flag2: false, flag3: true }
  ]
  </code></pre>
  
  <p>My question is, is it possible to call a method inside aggregate query?</p>
  
  <pre><code>aggregate({
      $project: {
          '_id': 1,
          'status' MyService.getStatus($flag1, $flag2, $flag3)
      }
  });
  </code></pre>
  
  <p>If it is possible, what is the syntax of it? Result:</p>
  
  <pre><code>[
      { _id: "Foo", status: 'ok' },
      { _id: "Bar", status: 'broken' }
  ]
  </code></pre>
  
  <hr>
  
  <p>In my real world application I have 10 boolean flags per document. If the user gets this documents I would like to convert the flags and give them a meaning (for the user). E.g. consider a document represents a tire. </p>
  
  <pre><code>flag1 = true means tire have good pressure, false means low pressure
  flag2 = true means depth of tire profile is good, false means little profile
  and so on
  </code></pre>
  
  <p>So in summary I would like to say a tire is OK if </p>
  
  <pre><code> flag1, flag2 are true and flag3 is false
  </code></pre>
  
  <p>and a tire needs to be replaced (BROKEN or REPLACE) when</p>
  
  <pre><code>flag1, flag2 are false and flag3 is true
  </code></pre>
  
  <p>When a document is returned to the user the flags should be removed. Instead we have the status field that says the tire is either OK or BROKEN.</p>