title: Mongoose sub field aggregation with full text search and project
body: <p>I have a <strong>Mongoose</strong> model called <strong>Session</strong> with a field named <strong>course</strong> (<strong>Course</strong> model) and I want to perform full text search on <strong>sessions</strong> with full text search, also I wanna aggregate results using fields from <strong>course</strong> sub field and to select some fields like <strong>course</strong>, <strong>date</strong>, etc.
  I tried the following:</p>
  <pre><code>Session.aggregate(
          [
              {
                  $match: { $text: { $search: 'web' } }
              },
              { $unwind: '$course' },
              {
                  $project: {
                      course: '$course',
                      date: '$date',
                      address: '$address',
                      available: '$available'
                  }
              },
              {
                  $group: {
                      _id: { title: '$course.title', category: '$course.courseCategory', language: '$course.language' }
                  }
              }
          ],
          function(err, result) {
              if (err) {
                  console.error(err);
              } else {
                  Session.deepPopulate(result, 'course course.trainer 
                    course.courseCategory', function(err, sessions) {
                    res.json(sessions);
              });
              }
          }
      );
  </code></pre>
  <p>My models:</p>
  <ul>
  <li>Session</li>
  </ul>
  <pre><code>    schema = new mongoose.Schema(
          {
              date: {
                  type: Date,
                  required: true
              },
              course: {
                  type: mongoose.Schema.Types.ObjectId,
                  ref: 'course',
                  required: true
              },
              palnning: {
                  type: [Schedule]
              },
              attachments: {
                  type: [Attachment]
              },
              topics: {
                  type: [Topic]
              },
              trainer: {
                  type: mongoose.Schema.Types.ObjectId,
                  ref: 'trainer'
              },
              trainingCompany: {
                  type: mongoose.Schema.Types.ObjectId,
                  ref: 'training-company'
              },
              address: {
                  type: Address
              },
              quizzes: {
                  type: [mongoose.Schema.Types.ObjectId],
                  ref: 'quiz'
              },
              path: {
                  type: String
              },
              limitPlaces: {
                  type: Number
              },
              status: {
                  type: String
              },
              available: {
                  type: Boolean,
                  default: true
              },
              createdAt: {
                  type: Date,
                  default: new Date()
              },
              updatedAt: {
                  type: Date
              }
          },
          {
              versionKey: false
          }
      );
  </code></pre>
  <ul>
  <li>Course</li>
  </ul>
  <pre><code>let schema = new mongoose.Schema(
      {
          title: {
              type: String,
              required: true
          },
          description: {
              type: String
          },
          shortDescription: {
              type: String
          },
          duration: {
              type: Duration
          },
          slug: {
              type: String
          },
          slugs: {
              type: [String]
          },
          program: {
              content: {
                  type: String
              },
              file: {
                  type: String
              }
          },
          audience: [String],
          requirements: [String],
          language: {
              type: String,
              enum: languages
          },
          price: {
              type: Number
          },
          sections: [Section],
          attachments: {
              type: [Attachment]
          },
          tags: [String],
          courseCategory: {
              type: mongoose.Schema.Types.ObjectId,
              ref: 'course-category',
              required: true
          },
          trainer: {
              type: mongoose.Schema.Types.ObjectId,
              ref: 'trainer'
          },
          trainingCompany: {
              type: mongoose.Schema.Types.ObjectId,
              ref: 'training-company'
          },
          status: {
              type: String,
              default: 'draft',
              enum: courseStatus
          },
          path: {
              type: String
          },
          cover: {
              type: String,
              required: true
          },
          duration: {
              type: Number,
              min: 1
          },
          createdAt: {
              type: Date,
              default: Date.now
          },
          updatedAt: {
              type: Date
          }
      },
      { versionKey: false }
  );
  </code></pre>
  <p>I am not sure if what I tried is gonna bring me what I want and I am getting this error concerning the <strong>$unwind</strong> operator:</p>
  <blockquote>
  <p>MongoError: exception: Value at end of $unwind field path '$course'
  must be an Array, but is a OID</p>
  </blockquote>
  <p>Any kind of help will be really appreciated.</p>