Skip to content

Polymorphic Embeddable Undefined Collection Error When Using EnsureIndexes #3013

@ThatOneAwkwardGuy

Description

@ThatOneAwkwardGuy

Describe the bug
I seem to be running into an error when setting ensureIndexes to true. When I remove my single use of a polymorphic embeddable in my code, I then stop receiving the error.

Stack trace

[0] [Nest] 28186  - 14/04/2022, 15:54:29   ERROR [ExceptionHandler] Collection name must be a String
[0] MongoInvalidArgumentError: Collection name must be a String
[0]     at checkCollectionName (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/mongodb@4.5.0/node_modules/mongodb/src/utils.ts:52:11)
[0]     at new Collection (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/mongodb@4.5.0/node_modules/mongodb/src/collection.ts:175:24)
[0]     at Db.collection (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/mongodb@4.5.0/node_modules/mongodb/src/db.ts:339:12)
[0]     at MongoConnection.getCollection (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@mikro-orm+mongodb@5.1.2_755b0c50a47b2e0e2c828f14e7a81037/node_modules/@mikro-orm/mongodb/MongoConnection.js:33:24)
[0]     at MongoSchemaGenerator.createPropertyIndexes (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@mikro-orm+mongodb@5.1.2_755b0c50a47b2e0e2c828f14e7a81037/node_modules/@mikro-orm/mongodb/MongoSchemaGenerator.js:100:33)
[0]     at MongoSchemaGenerator.ensureIndexes (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@mikro-orm+mongodb@5.1.2_755b0c50a47b2e0e2c828f14e7a81037/node_modules/@mikro-orm/mongodb/MongoSchemaGenerator.js:51:39)
[0]     at processTicksAndRejections (node:internal/process/task_queues:96:5)
[0]     at Function.init (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@mikro-orm+core@5.1.2_09d88bed54bceb13409f80c12f314721/node_modules/@mikro-orm/core/MikroORM.js:50:17)
[0]     at Injector.instantiateClass (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/injector.js:334:37)
[0]     at callback (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/injector.js:48:30)
[0]     at Injector.resolveConstructorParams (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/injector.js:122:24)
[0]     at Injector.loadInstance (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/injector.js:52:9)
[0]     at Injector.loadProvider (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/injector.js:74:9)
[0]     at async Promise.all (index 4)
[0]     at InstanceLoader.createInstancesOfProviders (/Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/instance-loader.js:44:9)
[0]     at /Users/moyogeorge/Documents/GitHub/clearcourt/node_modules/.pnpm/@nestjs+core@8.4.4_7c1be7e86cf9d53f4c225fc41118aa48/node_modules/@nestjs/core/injector/instance-loader.js:29:13

To Reproduce
Steps to reproduce the behavior:

  1. Create a polymorphic embeddable and use it in an entity.
  2. Attempt to ensureIndexes in the MikroOrm init

Expected behavior
No errors, and indexes to be created

Versions
"@mikro-orm/core": "5.1.2",
"@mikro-orm/migrations": "^5.1.2",
"@mikro-orm/mongo-highlighter": "1.0.0",
"@mikro-orm/mongodb": "5.1.2",
"@mikro-orm/nestjs": "5.0.1",
"@mikro-orm/reflection": "5.1.2",

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions