Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using Mongodb with mikroorm it does not recreate indexes and there seems to be no other way to drop indexes #3118

Closed
Loki-Afro opened this issue May 17, 2022 · 3 comments

Comments

@Loki-Afro
Copy link

Describe the bug
when using Mongodb with mikroorm it does not recreate indexes and there seems to be no other way to drop indexes.
We are using this.orm.getSchemaGenerator().ensureIndexes(); this only complaints about index definition mismatches, there is no way to simply drop indexes and recreate them in such cases.
If an orm can create indexes it should also care about their upgrade path
There is also no way to gather information from the resulting error since it basically pushed the mongodb error to the user without treating it accordingly (api leakage)

Stack trace

MongoServerError: Index with name: ldapDn_1 already exists with different options
    at MessageStream.messageHandler (/home/zarathustra/code/schulcloud-server/node_modules/mongodb/src/cmap/connection.ts:753:20)
    at MessageStream.emit (node:events:390:28)
    at processIncomingData (/home/zarathustra/code/schulcloud-server/node_modules/mongodb/src/cmap/message_stream.ts:168:12)
    at MessageStream._write (/home/zarathustra/code/schulcloud-server/node_modules/mongodb/src/cmap/message_stream.ts:65:5)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at MessageStream.Writable.write (node:internal/streams/writable:334:10)
    at Socket.ondata (node:internal/streams/readable:754:22)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12) {
  ok: 0,
  code: 85,
  codeName: 'IndexOptionsConflict'
}

To Reproduce
Steps to reproduce the behavior:

  1. define an entity with any kind of index
  2. let mikroorm create indexes
  3. change an existing index definition in an entity (nullable false -> nullable true for example)
  4. rerun {{ensureIndexes}} - exception occurs

Expected behavior
Indexes get recreated with an warning, most probably with another option to enable this feature

Versions

| Dependency | Version |
| node | v16.13.1 |
| typescript | 4.2.4 |
| mikro-orm | 5.0.5 |
| your-driver | mongodb |

@Loki-Afro
Copy link
Author

@totalard
Copy link

just put ensureindex: true in config

@B4nan
Copy link
Member

B4nan commented May 21, 2022

@totalard the problem is not with ensuring indexes, but that we only care about creating new indexes, not removing old indexes nor changing redefined ones.

@B4nan B4nan closed this as completed in 60fc7f6 Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants