moving obj traversal logic for upsert query conditions to upsert method