Sort array of metaobjects by value of field

I’m attempting to sort my array by the value of my order field in my metaobject. For example, each brand entry has brand.order which is an integer. How can i access these values and sort them before my for loop runs?

{% assign sorted_brands = shop.metaobjects.brands.values | sort: 'order' %}
{% for brand in sorted_brands %}
  {% if brand.category == category %}
    <li class="flex items-center justify-center">
      <a href="{{ brand.url }}" target="_blank" class="max-h-[44px] w-auto flex items-center justify-center">
        <img
          srcset="{{ brand.logo.value | image_url }}"
          src="{{ brand.logo.value | image_url }}"
          alt="{{ brand.name }}"
          height="44"
          width="86"
          class="max-h-[44px] w-auto"
          loading="lazy"
        >
      </a>
    </li>
  {% endif %}
{% endfor %}

Cast it into an array first, I don’t think sort will work on the base metaobject collection.

{% assign sorted_brands = shop.metaobjects.brands.values %}
{% assign sorted_brands = sorted_brands | sort: ‘order’ %}
{% for brand in sorted_brands %}
   …

This does break if you need to paginate since you can’t paginate arrays, but the default sort is the metaobject handle so you can just add a number in front to force an order on the backend.