Fix off-by-one error with metadata-mutating transactions.

Add some test cases for documents with trailing metadata, and fix an
off-by-one error in the metadata-mutating transactions (since the
document metadata array is one larger than the document data array).

Change-Id: I8f049466e03ed55010dfcf0a35702536edfa7b0a
Merge "Fix off-by-one error with metadata-mutating transactions."