ALClient icon indicating copy to clipboard operation
ALClient copied to clipboard

MongoBulkWriteError: E11000 duplicate key error collection

Open kevinsandow opened this issue 3 years ago • 2 comments

MongoBulkWriteError: E11000 duplicate key error collection: ..._alclient.entities index: serverRegion_1_serverIdentifier_1_name_1_type_1 dup key: { serverRegion: "US", serverIdentifier: "III", name: null, type: "mrpumpkin" }

This happens to mrpumpkin & mrgreen, in both cases the key part name is null.

So it's obviously this index that raises the issue:

EntitySchema.index({ name: 1, serverIdentifier: 1, serverRegion: 1, type: 1 }, { unique: true })

kevinsandow avatar Oct 23 '22 10:10 kevinsandow

Looks like there only is one place where the date is inserted:

https://github.com/earthiverse/ALClient/blob/f9ea72cec856ff7b0dc2704d7db60a297be87f91/source/Observer.ts#L162,L170

                if (Database.connection) {
                    EntityModel.updateOne({
                        serverIdentifier: this.serverData.name,
                        serverRegion: this.serverData.region,
                        type: data.name
                    }, monsterData, {
                        upsert: true
                    }).lean().exec().catch((e) => { console.error(e) })
                }

Since name isn't even used I would suggest to remove it from the index. Not sure though whether this will fix the issue.

kevinsandow avatar Oct 23 '22 10:10 kevinsandow

Same happened for snowman.

kevinsandow avatar Nov 03 '22 08:11 kevinsandow