title: Mongo aggregation with relevance match multiple fields
body: <p>Working from <a href="https://stackoverflow.com/questions/12770673/sorting-by-relevance-with-mongodb">this</a> other question, I am trying to gather entries that contain a keyword based on a user's search input. This is for a client's site, the schema is set up like this:</p>
  
  <pre><code>{
      fid: Number, // unique id for client's internal purposes
      email: String,
      password: String, // hashed
      name: {
          first: String,
          last: String
      },
      group: {
          name: String,
          description: String,
          type: String
      },
      bio: {
          short: String,
          long: String
      }
  }
  </code></pre>
  
  <p>And here is my query:</p>
  
  <pre><code>db.users.aggregate(
      [{
          $match: {
              $or: [
                  {
                      'name.first': {
                          $regex: userInput,
                          $options: 'i'
                       }
                  },
                  {
                      'name.last': {
                          $regex: userInput,
                          $options: 'i'
                      }
                  },
                  {
                      'bio.short': {
                          $regex: userInput,
                          $options: 'i'
                      }
                  },
                  {
                      'bio.long': {
                          $regex: userInput,
                          $options: 'i'
                      }
                  }
              ]
          },
          { $unwind: { '$name.first', '$name.last', '$bio.short', '$bio.long' } },
          {
              $match: {
                  $or: [
                      {
                          'name.first': {
                              $regex: userInput,
                              $options: 'i'
                           }
                      },
                      {
                          'name.last': {
                              $regex: userInput,
                              $options: 'i'
                          }
                      },
                      {
                          'bio.short': {
                              $regex: userInput,
                              $options: 'i'
                          }
                      },
                      {
                          'bio.long': {
                              $regex: userInput,
                              $options: 'i'
                          }
                      }
                  ]
              }
          },
          { $group: { _id: '$fid', hitCount: { $sum: 1 } } },
          { $sort: { hitCount: -1 } }
      }]
  );
  </code></pre>
  
  <p>For this type of query, I keep getting unexpected commas or end curly braces. I can't seem to find what I'm doing wrong (I've turned my mongodb.conf verbose logging up to 11). Where am I going wrong and am I even on the right path? I'd like to return each entry (object?) with all the info except the password field, how can I filter that out?</p>