Changing the order of copy and iNSERT

Changing the order of copy and iNSERT for mongoDB and PostgreSQL