We examined the community ecology of vaginal microbial samples taken from pregnant women with previous preterm birth experience to investigate whether targeted pathogenic and commensal bacteria are related to risk of preterm birth in the current pregnancy. We found a significant correlation between the community structure of selected bacteria and birth outcome, but the correlation differed among self-reported racial/ethnic groups. Using a community ordination analysis, we observed infrequent co-occurrence of Mycoplasma and bacteria vaginosis associated bacteria 3 (BVAB3) among black and Hispanic participants. In addition, we found that the vaginal bacteria responded differently in different racial/ethnic groups to modifications of maternal behavioral (ie, douching and smoking) and biological traits (ie, body mass index [BMI]). Even after accounting for these maternal behaviors and traits, the selected vaginal bacteria was significantly associated with preterm birth among black and Hispanic participants. By contrast, white participants did not exhibit significant correlation between microbial community and birth outcome. Findings from this study affirm the necessity of considering women’s race/ethnicity when evaluating the correlation between vaginal bacteria and preterm birth. The study also illustrates the importance of studying the vaginal microbiota from an ecological perspective, and demonstrates the power of ecological community analysis to improve understanding of infectious disease.