title: MongoDB Advanced Query - Getting data based on Array of objects
body: <p>On Mongo 2.4.6</p>
  
  <pre><code>Collection of Users
  {
      "_id" : User1,
       "orgRoles" : [ 
          {"_id" : 1, "app" : "ANGRYBIRDS", "orgId" : "CODOE"}, 
          {"_id" : 2, "app" : "ANGRYBIRDS", "orgId" : "MSDN"}
      ],
  },
  {
      "_id" : User2,
       "orgRoles" : [ 
          {"_id" : 1, "app" : "ANGRYBIRDS", "orgId" : "CODOE"}, 
          {"_id" : 2, "app" : "HUNGRYPIGS", "orgId" : "MSDN"}
      ],
  },
  {
      "_id" : User2,
       "orgRoles" : [ 
          {"_id" : 1, "app" : "ANGRYBIRDS", "orgId" : "YAHOO"}, 
          {"_id" : 2, "app" : "HUNGRYPIGS", "orgId" : "MSDN"}
      ],
  }
  </code></pre>
  
  <p>With data that looks like above, I'm trying to write a query to get:</p>
  
  <p>All the id's of the users that have only one ANGRYBIRDS app and that ANGRYBIRDS app is in the CODOE organization.</p>
  
  <p>So it would return User2 because they have 1 ANGRYBIRDS and is in the ORG "CODOE" but not User1 because they have two ANGRYBIRDS or User3 because they don't have an ANGRYBIRDS app in the "CODOE" organization. I'm fairly new to mongo queries, so any help is appreciated.</p>