title: What is the right way to select records from mongodb document
body: <p>I"m new in <strong>mongodb</strong> and I really like the idea of noSql.</p>
  
  <p>I"m trying to build a blog where on each comment people can click on rate buttons and rate the person comment.</p>
  
  <p>Inside each comment I have a array of votes where there is a vote type and unique IP.
  Each user click on button will insert line (once per IP).</p>
  
  <p><strong>At the end I want to query documents/posts and get the information in the following structure, CalculatedVotes, distinct VoteType, Caption and count</strong></p>
  
  <p><strong>The result that I want to retrieve</strong></p>
  
  <pre>
     {
      PostTitle:"This is a blog post",
      Posted:"12/12/2012",
      ByUsertId:"2",
      Body:"This is a simple body"
      Comments:
      [
          {
              PostedBy:"someUser",
              Text:"Hi There!",
              CalculatedVotes:
              [
                  {
                      VoteType:"AGREE",
                      Caption="I agree!",
                      Count:2
                  },
                  {
                      VoteType:"NOT_AGREE",
                      Caption="No Way!",
                      Count:1
                  },
              ]
          },
          {
              PostedBy:"someUser2",
              Text:"Whats up?",
              CalculatedVotes:
              [
                  {
                      VoteType:"AGREE",
                      Caption="I agree!",
                      Count:1
                  },
                  {
                      VoteType:"NOT_AGREE",
                      Caption="No Way!",
                      Count:2
                  },
              ]
          }
      ]
  
      }
  
  </pre>
  
  <p><strong>Document structure</strong></p>
  
  <pre>
  {
      PostTitle:"This is a blog post",
      Posted:"12/12/2012",
      ByUsertId:2,
      Body:"This is a simple body"
      Comments:
      [
          {
              PostedBy:"someUser",
              Text:"Hi There!",
              Votes:
              [
                  {
                      VoteType:"AGREE",
                      Caption="I agree!",
                      IP:"1.1.1.1"
                  },
                   {
                      VoteType:"NOT_AGREE",
                      Caption="No Way!",
                      IP:"2.2.2.2"
                  },
                   {
                      VoteType:"AGREE",
                      Caption="I agree!",
                      IP:"3.3.3.3"
                  }
              ]
          },
          {
              PostedBy:"someUser2",
              Text:"Whats up?",
              Votes:
              [
                  {
                      VoteType:"NOT_AGREE",
                      Caption="No Way!",
                      IP:"1.1.1.1"
                  },
                   {
                      VoteType:"NOT_AGREE",
                      Caption="No Way!",
                      IP:"2.2.2.2"
                  },
                   {
                      VoteType:"AGREE",
                      Caption="I agree!",
                      IP:"3.3.3.3"
                  }
              ]
          }
      ]
  
  }
  </pre>