added error checking for $unwind pipeline operator