Spring Data MongoDB: How ignore unique indexed field when Document is embedded in another one?

人盡茶涼 提交于 2019-12-04 05:12:52

Simply add @Reference like this:

@Document
public class Version {

  @Id
  private String id;

  @Reference
  private Contract contract;

  private Instant createdAt;

  // getter & setter & hashcode & equals & tostring...
}

I am not sure if there is a way to achieve this from spring context.

The best way is to remove all the indices definition outside of your code. i.e apply through an offline script. You can apply scripts using tools like mongeez. It can be configured to run on application startup, so you can ensure its always run irrespective of location.

Once the application is live we might want to build new indices in a controlled manner. Having embedded in the code may not give this advantage as it will run only on startup.

If you are using offline scripts you are in total control.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!