Dynamic date calculation and compare issue in atlas trigger function

Hi Folks,

My function in trigger is not giving any result. I think date is creating problem. aggregation works fine in mongosh. Can you point out issue and possible fix.

exports = function() {
	let collections = context.services.get("xxx").db("xxx");
	let orderhistoryCollection = collections.collection("xxx");
  let idList= orderhistoryCollection.aggregate([
  {
    $addFields: {
      created_at: {
        $toDate: "$creationDate",
      },
    },
  },
  {
    $match: {
      $and: [
        {
          creationDate: {
            $ne: "",
          },
        },
        {
          created_at: {
            $lt: {$date:getThreshholdDate()},
          },
        },
      ],
    },
  },
  {
    $project: {
      _id: "$_id",
    },
  },
]);
console.log("JSON List"+JSON.stringify(idList));
};

function getThreshholdDate() {
 let date = new Date();
 let orderstartDate =date.setMonth( date.getMonth() - 7 );
 return orderstartDate;
}

Thanks in Advance!