Through tunning the N and O coordintion donors in piperazine and morpholine derivatives, six POM-based compounds were obtained, namely [CuII(tep)][HCr(OH)6Mo6O18]·H2O (1), [CoII(tep)2][H4(γ-Mo8O26)] (2), [AgI2(tem)4][H2PW12O40]2·2H2O (3), [M(tem)2][H2(γ-Mo8O26)] (M = CuII 4, CoII 5, ZnII 6) (tep = 1-(2-(4H-1,2,4-Triazol-4-yl)ethyl)piperazine, tem = 4-(2-4H-1,2,4-Triazol-4-yl)ethyl)morpholine). Compounds 1–6 show 0D, 1D, 2D and 3D structures, respectively. In compound 1, two Anderson type anions hang on either side of the copper dimer [Cu2(tep)2]4+, forming a discrete structure. In compound 2, the N donor in piperazine coordinates with a Co atom, inducing a 3D framework. Compond 3 exhibits a 0D structure containing discrete Keggin anions and binuclear [Ag2(tem)4]2+ clusters. Compounds 4, 5 and 6 are isostructural, showing 3D grid structures with 2D POM-based layers linked by metal-organic lines. Compounds 2, 4, 5 and 6 contain Mo–N bonds to enhance structural stability. Tunning N and O coordintion donors in tep and tem ligands is reasonable to construct different POM-based compounds. Furthermore, the electrochemical and selective photocatalytic properties of the title compounds were also studied. Compound 3 can act as a fluorescence sensor for sensing Hg2+.