node.js – How to ignore a mongo pipeline stage conditionally based on field values?

  "items.product.title": {
    $arrayElemAt: ["$ware_type.product.title", 0] 
  "items.product.code": {
    $arrayElemAt: ["$ware_type.product.code", 0] 

This is a stage in my query pipeline. Sometimes items field is an empty array and some other times it has items which include product field. I want to make a condition for the execution or complete ignorance of this stage based on that. So, when items is an empty array I want to completely skip this stage and I don’t mean assigning null values or so. How can I create a condition for the execution of a stage?