Squash Upsert provided doc.

Squash made for easy PR handling. Upsert provided doc.

Added shouldUpsertDoc

Added shouldUpsertDoc so that it doesn't need to send several docs over
the wire.

Adjusted to be less intrusive

Change upsert_doc to doc_as_upsert as well

Removed unused assignments