Sort subdocuments in arrays before comparing them