Correctly handle assigning nested document to/from nil