Inertialess magnetohydrodynamic flows in expansions and contractions