I have a spring boot project where I use MongoDb-reactive and webflux.
I have entites that have a UUID as an _id. I'm trying to write an endpoint that accepts an UUID and returns the matching object.
Since findById accepts Strings, I tried to use it with id.toString() but my repository doesn't seem to find anything. My guess is that MongoDB doesn't returns the UUID as a plain string, but I can't figure out how it is saved.
My working solution for now are custom methods in the repository, which accepts UUID as parameters but there has to be another way using stringsp
Your
idfield should be a String, annotated with@Id. It shouldn't be a UUID type.You should be able to use your Spring Data Repository of choice to call
.findById.