What is the role of the user to acquire a lock in mongodb

what is the role of the user to acquire a lock in mongodb.

Hi @padmaja, not clear what do you mean. In order for liquibase-mongodb to be able to create its tracking collection and insert the lock the user has to have createCollection and usual DML privileges. From specific permission it has to have colMod privilege as during run it adjusts the tracking table validators. Can be turned off from properties.

Would be helpful if you paste some logs with the exception you are getting

Caused by: com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'not authorized on DBNAME to execute command { collMod: DATABASECHANGELOGLOCK, validator: { $jsonSchema: { bsonType: object, description: Database Lock Collection, required: [ _id, locked ], properties: { _id: { bsonType: int, description: Unique lock identifier }, locked: { bsonType: bool, description: Lock flag }, lockGranted: { bsonType: date, description: Timestamp when lock acquired }, lockedBy: { bsonType: [ string, null ], description: Owner of the lock } } } }, validationLevel: strict, validationAction: error, $db: DBNAME, at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:175)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:302)
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:258)
at com.mongodb.internal.connection.UsageTrackingInternalConnection.sendAndReceive(UsageTrackingInternalConnection.java:99)
at com.mongodb.internal.connection.DefaultConnectionPool$PooledConnection.sendAndReceive(DefaultConnectionPool.java:450)
at com.mongodb.internal.connection.CommandProtocolImpl.execute(CommandProtocolImpl.java:72)
at com.mongodb.internal.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:226)
at com.mongodb.internal.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:269)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:131)
at com.mongodb.internal.connection.DefaultServerConnection.command(DefaultServerConnection.java:123)
at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:343)
at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:334)
at com.mongodb.operation.CommandOperationHelper.executeCommandWithConnection(CommandOperationHelper.java:220)
at com.mongodb.operation.CommandOperationHelper$5.call(CommandOperationHelper.java:206)
at com.mongodb.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:463)
at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:203)
at com.mongodb.operation.CommandOperationHelper.executeCommand(CommandOperationHelper.java:198)
at com.mongodb.operation.CommandReadOperation.execute(CommandReadOperation.java:59)
at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:194)
at com.mongodb.client.internal.MongoDatabaseImpl.executeCommand(MongoDatabaseImpl.java:194)
at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:163)
at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:158)
at com.mongodb.client.internal.MongoDatabaseImpl.runCommand(MongoDatabaseImpl.java:148)
at liquibase.ext.mongodb.lockservice.AdjustChangeLogLockCollectionStatement.run(AdjustChangeLogLockCollectionStatement.java:67)
at liquibase.ext.mongodb.statement.AbstractRunCommandStatement.execute(AbstractRunCommandStatement.java:50)
at liquibase.ext.mongodb.lockservice.AdjustChangeLogLockCollectionStatement.execute(AdjustChangeLogLockCollectionStatement.java:52)
at liquibase.ext.mongodb.lockservice.AdjustChangeLogLockCollectionStatement.execute(AdjustChangeLogLockCollectionStatement.java:30)
at liquibase.nosql.executor.NoSqlExecutor.execute(NoSqlExecutor.java:181)

This is the error log I am getting .it is failing while validating the JSON schema.colMod privilege I think it is required.Can it be disabled if so how it impacts the Liquibase functionality.Thanks.

Hi @padmaja of cause first option would be to grant colMod to the user :slight_smile: .

Second option would be to pass -Dliquibase.mongodb.supportsValidator=false
The effect is that tracking collections will not have strict validators. Not impacting liquibase logic however if you change something manually into tracking collections(not wanted action) it will not be validated by mongo.

When run from mvn or java -jar just pass the env variable
When run from CLI you have to pass via JAVA_OPTS

For example you can amend liquibase.bat this way or set at higher level:

IF NOT DEFINED JAVA_OPTS set JAVA_OPTS=

set JAVA_OPTS=%JAVA_OPTS% -Dliquibase.mongodb.supportsValidator=false