How can I sort a MongoDB collection in a Node.js application based on the query string provided in the URL?
The URL looks like this: http://localhost:5000/v1/bid/sort_bid?sort={"_id": -1,"enquiry_no": 1}
I am trying to pass an object in the code below:
const getSortedBidList = catchAsync(async (req, res) => {
let { sort } = req?.query;
console.log('Query String', sort);
let object = new Object();
object[sort] === 1 ? 'ASC' : 'DESC';
let result = await Bid
.find({})
.sort(object)
.limit(limit)
.skip(offset);
} I have tried passing the query string object in the sort method, but it is not working as expected. Any help or suggestions would be greatly appreciated. Thank You