title: How to use if condition in mongodb aggregate in node.js depends on the input
body: <p>How can i add an if condition between the aggregate function, assuming I have one parameter from the request "input", if i have the input i would like to look id's greater than that id, if i don't have the input, i won't be matching the id, how can i achieve that?</p>
  
  <pre><code>collection.aggregate(
          // Pipeline
          [
              // Stage 1 
              {
                  $match: {
                      "created_at": {$gte: fromDate, $lt: toDate},
                      "type": {$in : typeArray},
                      if (input){
                         "_id": {$gte: ObjectId("blahblahblah")}
                      }
                  }
              },
              {
                  $lookup: // Equality Match
                      {
                          from: "users",
                          localField: "some_id",
                          foreignField: "_id",
                          as: "user"
                      }
              },
              {
                  $sort: 
                  {
                      "_id": 1
                  }
              },
              {
                  $limit: pageSize
              }
          ])
  </code></pre>