I'm trying to create a reference to another model in Spring MognoDB.
I have a list of documents previously inserted into MongoDB using Mongoose so the references look like this:
{
...
address: ObjectId("5f596acb8ea1d54128016e97")
}
Following the Spring MongoDB documentation, I created two models:
@Document(collection = "person")
public class Person{
@Id
private String id;
... other attributes
@DBRef
private Address address;
}
Second model:
@Document(collection = "address")
public class Address{
@Id
private String id;
... other attributes
}
However this fails to return a document, showing the following error:
No converter found capable of converting from type [org.bson.types.ObjectId] to type [....models.Address]
Any idea how to solve this problem?
I also tried changing the id type to ObjectId but still getting the same error.