generic code for mongo and mysql