Skip to content

Identifier conversion not considered during @DocumentReference construction #3782

Closed
@blueiceprj

Description

@blueiceprj

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.

  1. dataType parameter on DocumentReference annotation class. (example : ObjectId, String ...)
  2. Or custom lookup field.
@DocumentReference(lookup = "{ '_id' : new ObjectId('?#{#target}') }")
private Country country;

or

@DocumentReference(lookup = "{ '_id' : { $oid: '?#{#target}' } }")
private Country country;
  1. Spring should get the data type of referenced document and according to prepare lookup query

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions