title: Mongo aggregrate conditional $match, $group and $project
body: <p>My collection has document structure like below:</p>
  
  <pre><code>{ AppName: 'test',
  AppEnv: 'Development'
  AppTech:'Java'
  AppVersion: '1_0',
  
  AppName: 'test',
  AppEnv: 'SQA'
  AppTech:'Java'
  AppVersion: '1_0',
  
  AppName: 'test22',
  AppEnv: 'Development'
  AppTech:'Java'
  AppVersion: '1_2',
  
  AppName: 'test22',
  AppEnv: 'SQA'
  AppTech:'Java'
  AppVersion: '1_1',
  
  AppName: 'test22',
  AppEnv: 'Production'
  AppTech:'Java'
  AppVersion: '1_0',
  
  AppName: 'test2',
  AppEnv: 'Development'
  AppTech:'.NET'
  AppVersion: '1_0'
  
  }
  </code></pre>
  
  <p>I need to get AppVersion based on AppName/AppEnv/AppTech provided.For eg:</p>
  
  <p>AppVersion(with some flag) based on AppEnv of all whose AppTech is 'Java'. The result could look like below:</p>
  
  <pre><code>{
  AppName: 'test', 
  AppTech: 'Java',
  VersionInfo: [AppEnv: {'Development','SQA'}, AppVersion: {'1_0','1_1'}],
  hasVersionDiff: 'false',
  
  AppName: 'test22', 
  AppTech: 'Java',
  VersionInfo: [AppEnv: {'Development','SQA','Production}, AppVersion: {'1_2','1_1','1_0'}],
  hasVersionDiff: 'true'
  
  }
  </code></pre>
  
  <p>Can someone please suggest me how do i start writing queries for this?</p>