Fix to object conversion on after sortBy

After sortBy is called on a collection it is no longer an array but an object when the collection is outputted with toJson(). This makes sure it is still sorted, but it remains an array.