Hello @Chris_Job1, Welcome back to the MongoDB community forum,
I can see you have assigned the value in sortBy variable but not used it in the aggregation query, you have written the property name statically { sortBy: -1 }, and that will not refer to the variable,
You can try this, wrapping property name in array blocks [sortBy],
var sortBy = “deliveryDate”
db.orders.aggregate([{$match:{}}, {$sort: {[sortBy]: -1}}, {$limit: 10}])