can't create an index with mongock on a mongodb collection

184 Views Asked by At

Each time I try to create an index on a collection with mongock I have this error:

Command createIndexes does not support this transaction's { readConcern: { level: "majority", provenance: "clientSupplied" } } :: caused by :: read concern not supported

my code :

@ChangeUnit(id = "init-index", order = "3", author = "mongock", transactional = false)
@Component
open class InitIndex(
    @NonLockGuarded
    private val ordersMongoTemplate: MongoTemplate,
    @NonLockGuarded
    private val env: Environment,
    @NonLockGuarded
    private val mongoOperations: MongoOperations,
) {
    @Execution
    open fun execution() {
        val expirationPeriod = "P6666D"

        mongoOperations
            .indexOps("myCollection")
            .ensureIndex(
                Index("myField", Sort.Direction.ASC)
                    .named("myField")
                    .expire(Duration.parse(expirationPeriod))
                    .background()
            )

    }

any idea what it is?

1

There are 1 best solutions below

0
Mongock team On

Mongock provides @BeforeExecution annotation for those operations that need to be executed without transaction scope. You can add an additional method to your ChangeUnit for that purpose.

Please take a look to the documentation and examples in the following link.