Closed
Description
Hi,
I use the new feature of document reference annotation @DocumentReference and have a issue about it. In case I have Country and City documents and City referenced to Country with this annotation. But "_Id" field of type on Country document is ObjectId. I write this code on City document as well:
@DocumentReference
private Country country;
When I get Country of City object it couldn't fetch data and return null. Because of Country document reference stored as String type. I think there is a type mismatch on lookup query.
I think we need like 2 options on document reference.
- dataType parameter on DocumentReference annotation class. (example : ObjectId, String ...)
- Or custom lookup field.
@DocumentReference(lookup = "{ '_id' : new ObjectId('?#{#target}') }")
private Country country;
or
@DocumentReference(lookup = "{ '_id' : { $oid: '?#{#target}' } }")
private Country country;
- Spring should get the data type of referenced document and according to prepare lookup query