title: Mongodb using $text in aggregate query
body: <p>I'm trying to search in text with aggregate and I have the following code.Here is my aggregate query, but doesn't work. I expect to search first for the text and if find posts with that words in it to find user and then to query by user.name and the topic.</p>
  <pre><code>const posts = await Post.aggregate([
        {
          $match: {
            $text: {
              $search: postWords ? `${postWords}` : /.*/,
              $caseSensitive: false,
            },
          },
        },
        {
          $lookup: {
            from: &quot;users&quot;,
            localField: &quot;user&quot;,
            foreignField: &quot;_id&quot;,
            as: &quot;user&quot;,
          },
        },
        {
          $unwind: &quot;$user&quot;,
        },
        {
          $match: {
            $and: [
              {
                topic: {
                  $regex: postTopic ? postTopic : /.*/,
                  $options: &quot;i&quot;,
                  $exists: true,
                },
              },
              {
                &quot;user.name&quot;: {
                  $regex: postName ? postName : /.*/,
                  $options: &quot;i&quot;,
                  $exists: true,
                },
              },
              { text: { $regex: postWords ? postWords : /.*/, $options: &quot;i&quot; } },
            ],
          },
        },
        {
          $skip: req.params.page ? (req.params.page - 1) * 10 : 0,
        },
        {
          $limit: 11,
        },
        {
          $project: {
            &quot;user.password&quot;: 0,
            &quot;user.active&quot;: 0,
            &quot;user.email&quot;: 0,
            &quot;user.temporaryToken&quot;: 0,
          },
        },
      ]);
  </code></pre>