I have a Snozberry object that looks like this:
{
"id":"3cbdb746-561d-4e21-82e0-b7cfcad3a094",
"thingId":"7cbfb7a6-763d-6ef1-271b-b2a0cfc2fa43",
"stuffId":81,
"bits":"WooHoo"
}
Java class (constructor, getter & setters omitted for brevity):
@Document(collection="Snozberry")
public class Snozberry {
@Id
private UUID id;
private UUID thingId;
private Long stuffId;
private String bits;
}
The repository looks like:
public interface SnozberryRepository extends MongoRepository<Snozberry,UUID>{
Snozberry findByThingId(UUID Id);
Snozberry findById(UUID id);
}
In the MongoDb collection, the _id & thingId fields are defined as a UUID. I would like to return the document that matches the id value I pass in.
I can return all objects using findAll() and I can return objects matching thingId by using the
Snozberry findByThingId(UUID id)
method defined in my repository, so I know it's talking to the DB ok, and that it can find (non Id) UUID fields ok.
I've tried the default
findOne(UUID.fromString("3cbdb746-561d-4e21-82e0-b7cfcad3a094")
and i've also called this method defined in the repository
Snozberry findById(UUID id)
But both of those return null. What am I missing (feels like it's something that should be obvious).
Thanks M