Im having a requirement to create mongodb collections by tenant specific. Eg: I have a collection called audit_logs, but I want to create the following way
tenant : EAD collection : ead_audit_logs tenant : gtc collection : gtc_audit_logs and so on.
somebody please help me to do the configuration in micronaut.
im using micronaut-data and the configuration to be done in the pojo/entity class is not working out.
@Getter
@Setter
@MappedEntity
@Property(name = "#{@ThreadContext.get('tenant')}_audit_log")
public class AuditLog {
@Id
@GeneratedValue
private String id;
}
The code you provided is not valid because the
@Propertyannotation on the class entity doesn't have any effect. To achieve the desired result, You can provide a custom implementation for theMongoCollectionNameProviderinterface.Example:
In the above example, we have overridden the
providemethod in theMongoCollectionNameProviderinterface. You can add your collection naming logic to this method.And make sure to annotate the class with
@Primaryand@Singleton. This will ensure that the custom implementation overrides the default bean DefaultMongoCollectionNameProvider.