title: Mongodb selecting all fields and conditional field selection in project stage
body: <p>I have a schema with 50 fields and I need to select all fields, but, one field I want to select based on some criteria, for that I wrote following code:</p>
  <pre><code>const _tours = await Tour.aggregate()
          .match({booked: true})
          .project({
              &quot;bookedByTask&quot;: {
                  $cond: {
                      if: {
                          '$in': ['$bookedByTask.tasks.taskId', req.body.taskIds]
                      },
                      then: &quot;$bookedByTask&quot;,
                      else: &quot;$$REMOVE&quot;
                  }
              }
          });
  </code></pre>
  <p>but the code returns only <code>_id</code> and <code>bookedByTask</code> fields, I need all other fields as well, and I don't want to include all fields by hand, because it will become maintenance nightmare.</p>