Search code examples
nestjsmikro-orm

NestJS - MikroORM how to get id after creation


I'm using MikroORM in my newest project and I was wondering, is it possible to return the newly created record id? Thank you for your help


Solution

  • It will be available on the entity once you flush:

    const user = new User();
    em.persist(user);
    await em.flush();
    console.log(user.id);