Handle ODM document upserts

Fixes issues: #994 , #1053 and #1105