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

**URL:** <https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190>\
**Category:** General Discussion\
**Created:** [March 12, 2021, 12:28am UTC](https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190 "2021-03-12T00:28:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![padmaja](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@padmaja](https://forum.liquibase.org/u/padmaja)\
**Post date:** [March 12, 2021, 12:28am UTC](https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190/1 "2021-03-12T00:28:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexandru.slobodcico](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/alexandru.slobodcico/32/334_2.png) [@alexandru.slobodcico](https://forum.liquibase.org/u/alexandru.slobodcico)\
**Post date:** [March 15, 2021, 1:10pm UTC](https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190/2 "2021-03-15T13:10:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![padmaja](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@padmaja](https://forum.liquibase.org/u/padmaja)\
**Post date:** [March 15, 2021, 3:54pm UTC](https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190/3 "2021-03-15T15:54:01Z")

</div>

| 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.

---

<div class="post-metadata">

**Author:** ![alexandru.slobodcico](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/alexandru.slobodcico/32/334_2.png) [@alexandru.slobodcico](https://forum.liquibase.org/u/alexandru.slobodcico)\
**Post date:** [March 16, 2021, 8:34am UTC](https://forum.liquibase.org/t/what-is-the-role-of-the-user-to-acquire-a-lock-in-mongodb/5190/4 "2021-03-16T08:34:20Z")

</div>

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

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
