Implement mostly-Mongo-compatible sorting in the presence of arrays.