In this case I think you'll need to use a naming convention for your VMs running databases. e.g. db-mysql or db-mongo
Then you can list the servers and iterate over the results to check for VMs that what with the db- prefix.
If you're using the ComputeService, you could use
ComputeService.listNodesDetailsMatching(Predicate<ComputeMetadata>)
If you're using the ServerApi, you could use
ServerApi.list()