UTI???

I went to the doctor and they took a sample swab from my vagina (I’m pregnant) and I have a UTI. Just wondering how do they know? Is there bacteria that would show up on the swab? Also what else can they see from a swab from the Vagina? I’m curious