Context. Ultracompact (UC) Hii regions constitute one of the earliest phases in the formation of a massive star and are characterized by extreme physical conditions (G 0 > 10 5 Habing field and n > 10 6 cm −3 ). The UC Hii Mon R2 is the closest example and an excellent target to study the chemistry in these complex regions. Aims. Our goal is to investigate the chemistry of the molecular gas around UC Hii Mon R2 and the variations caused by the different local physical conditions. Methods. We carried out 3 mm and 1 mm spectral surveys using the IRAM 30-m telescope towards three positions that represent different physical environments in Mon R2: (i) the ionization front (IF) at (0 , 0 ), and two peaks in the molecular cloud; (ii) molecular Peak 1 (hereafter MP1) at the offset (+15 , −15 ); and (iii) molecular Peak 2 (hereafter MP2) at the farther offset (0 , 40 ). In addition, we carried out extensive modeling to explain the chemical differences between the three observed regions. Results. We detected more than 30 different species (including isotopologues and deuterated compounds). In particular, we detected SO + and C 4 H confirming that ultraviolet (UV) radiation plays an important role in the molecular chemistry of this region. In agreement with this interpretation, we detected the typical photo-dissociation region (PDR) molecules CN, HCN, HCO, C 2 H, and c-C 3 H 2 . There are chemical differences between the observed positions. While the IF and the MP1 have a chemistry similar to that found in high UV field and dense PDRs such as the Orion Bar, the MP2 is similar to lower UV/density PDRs such as the Horsehead nebula. Our chemical modeling supports this interpretation. In addition to the PDR-like species, we detected complex molecules such as CH 3 CN, H 2 CO, HC 3 N, CH 3 OH, and CH 3 C 2 H that are not usually found in PDRs. The sulfur compounds CS, HCS + , C 2 S, H 2 CS, SO, and SO 2 and the deuterated species DCN and C 2 D were also identified. The origin of these complex species requires further study. In Mon R2, we have the two classes of PDRs, a high UV PDR towards the IF and the adjacent molecular bar, and a low-UV PDR, which extends towards the north-west following the border of the cloud.