adding mongo error check code