move upsert logic into the accounts collection