title: if condtion MongoDB aggregation
body: <p>I need to display the currentLocation of which the process is completed,which are presented in four different collections. It's a chain process, in the order of labtest, inwards, goods, production. Each of them is different collections. I want the result in which, if labtest status is completed it goes to inwards, if inwards status also completed, then it goes and checks on goods. If goods status is In-Progress, it should return Inwards as currentLocation.</p>
  
  <p>But, I am getting a response as  Production....it seems like me if the condition is not working. Please help me to solve this issue</p>
  
  <pre><code>async function getGrnDetails(userParam) {
    var user = User.findOne({ grnNo: userParam.grnNo })
      var userss = User.aggregate([
  
          {
              $match:
              {
  
                  grnNo: userParam.grnNo
  
              }
          }, {
              $lookup: {
                  from: "goods",
                  let: { grnNo: "$grnNo" },
                  pipeline: [
                      {
                          $match: {
                              $expr:
                              {
                                  $eq: ["$grnNo", '$$grnNo']
                              }
                          }
                      },
                  ],
                  as: "Goods",
  
              },
          },
          {
              $lookup: {
                  from: "inwards",
                  let: { grnNo: "$grnNo" },
                  pipeline: [
  
                      {
                          $match: {
                              $expr:
                              {
                                  $eq: ["$grnNo", '$$grnNo']
                              }
                          }
                      }
                  ],
                  as: "Inwards",
  
  
              }
          },
          {
              $lookup: {
                  from: "productions",
                  let: { grnNo: "$grnNo" },
                  pipeline: [
                      {
                          $match: {
                              $expr:
                              {
                                  $eq: ["$grnNo", '$$grnNo']
                              }
                          }
                      },
                  ],
                  as: "Productions",
              }
          },
          {
              $unwind: {
                  "path": "$Productions"
              }
          },{
              $unwind: {
                  "path": "$status"
              }
          },{
              $unwind: {
                  "path": "$Goods"
              }
          },
  
          {
              $unwind: {
                  "path": "$Inwards"
              }
          },
          {
              $group: {
                  "_id": {
                      beforeHeadSettingArray: '$beforeHeadSettingArray',
                      beforeWashingArray: '$beforeWashingArray', id: '$id',
                      status: '$status', defaultAccountId: '$defaultAccountId',
                      beforeStenterArray: '$beforeStenterArray',
                      beforeCompactingArray: '$beforeCompactingArray',
                      afterCompactingArray: '$afterCompactingArray',
                      status: "$status",
                      Goods: '$Goods.processArray', Inwards: '$Inwards.fabricArray', Production: '$Productions.operationDisplay', currentLocation: {
  
                          $cond: {
                              if: {
                                  $strcasecmp: ["$status", "Completed"]
                              }, then: {
                                  $cond: {
                                      if: {
                                          $strcasecmp: ["$Inwards.status", "Completed"]
                                      },
                                      then: {
                                          $cond: {
                                              if: {
                                                  $strcasecmp: ["$Goods.status", "Completed"]
                                              },
  
                                              then:
                                              {
                                                  $cond: {
                                                      if: {
                                                          $strcasecmp: ["$Productions.status", "Completed"]
                                                      },
  
                                                      then: "Productions",
                                                      else: "Goods"
                                                  }
                                              },
                                              else: "Inwards"
                                          }
                                      },
                                      else: "LabTest"
                                  }
                              },
                              else: "Yet To be Started"
  
                          }
                      }
                  },
                  "ProgressArray": {
                      $addToSet: {
                          "Inwards": "$Inwards.status",
                          "Goods": "$Goods.status",
                          "Productions": "$Productions.status",
                          "LabTest": "$status"
                      },
                  }
  
  
  
  
              }
          }  ,{ $sort: { _id: 1 } },
          { $limit: 1 }
  
      ]);
  
  
      return await userss
  }
  </code></pre>