zakodium / adonis-mongodb

MongoDB provider for AdonisJS 5
https://zakodium.github.io/adonis-mongodb/
Other
64 stars 12 forks source link

Running migration fails when creating an index #62

Open MadScripter opened 3 years ago

MadScripter commented 3 years ago

When trying to run a migration that creates an Index, it fails with the following error:

The migration:

import BaseMigration from '@ioc:Mongodb/Migration'

export default class UsersMigration extends BaseMigration {
    public up(): void {
        this.createCollection('Users')
        this.createIndex('Users', 'SteamId', { unique: true })
    }
}

The error:

MongoError: writeConcern is not allowed within a multi-statement transaction

at MessageStream.messageHandler (<path_to_project>\node_modules\mongodb\lib\cmap\connection.js:268:20)
at MessageStream.emit (events.js:315:20)
at processIncomingData (<path_to_project>\node_modules\mongodb\lib\cmap\message_stream.js:144:12)
at MessageStream._write (<path_to_project>\node_modules\mongodb\lib\cmap\message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:719:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (internal/streams/readable.js:309:12)
at readableAddChunk (internal/streams/readable.js:284:9) {
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 11, high_: 1619974922 },
  ok: 0,
  code: 72,
  codeName: 'InvalidOptions',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 11, high_: 1619974922 },
    signature: { hash: [Binary], keyId: [Long] }
  }
}

However when removing the line that creates the index, the migration runs just fine.