Chinese fir forests play a significant role both economically and ecologically, contributing to soil and water conservation while also serving as an efficient timber-producing species that brings economic benefits. However, the issue of soil degradation due to continuous Chinese fir planting cannot be overlooked. Continuous planting leads to a decrease in soil nutrients, a reduction in microbial diversity, and changes in microbial community composition, which in turn affect the abundance of carbon and nitrogen cycle functional genes in Chinese fir forest soils. We utilized metagenomic sequencing technology to investigate the dynamics of microbial community composition and carbon and nitrogen-related functional genes in the soils of Chinese fir forests across different plantation generations, exploring their relationship with soil carbon and nitrogen nutrients. We found that the relative abundance of bacterial communities is dominant in both phylum and genus levels within microbial communities. The partial least squares path models (PLS-PM) indicated that planting generations had a negative effect on dissolved organic carbon (DOC), nitrate nitrogen (NO