mysqltypescriptnestjsmikro-orm

Is there a way to exclude fields during select in MikroORM?


I want to select some 100 fields in a nested populate query in MikroORM with MySQL and just want to leave out some 20 fields. Leaving 20 makes more sense to me, instead of selecting 100, something like db.find().select("-password") in MongoDB. The documentation seems to have only documented Partial Fetches where I can select fields not unselect them.


Solution

  • Since v6.0.0 you can use exclude option, which will omit the provided properties and select everything else.

    const authorWithoutEmail = await em.findOne(Author, '...', {
      exclude: ['email']
    });
    

    https://mikro-orm.io/docs/entity-manager#partial-loading