Removed the pg_size_pretty function from query for the collection and introduced the client side function to convert size into human readable format. So, the sorting issue is fixed as the algorithm will get the actual value of size instead of formatted value.