@Id and @Field on same variable?

2019-07-15 04:19发布

问题:

Is there a way to achieve @Id and @Field on the same variable of a @Document so the variable is also saved inside the document? I'm trying to preserve the data I'm importing as much as I can, even though I get the design practices followed by the developers.

回答1:

The @Id annotation will take priority over @Field, so no the id cannot be persisted as both document ID and value inside the document. Quickest way to achieve that is probably to duplicate the id field as a separate @Field annotated attribute?