TypeOrm & MongoDB: Column aliases ignored on insert/save

Viewed 353

When using column aliases with MongoDB, TypeORM does not use the alias (Column name) when inserting/updating records, it only uses it when querying data.

Expected Behavior

When declaring a class like this

@Entity({ name: 'users' })
export class User {
   @ObjectIdColumn() readonly id: ObjectID;
   @Column({ name: "first_name" }) firstName: string;
}

and inserting a new record with a MongoRepository like this

const newUser = this.usersRepository.create({ firstName: 'Joe' });
return await this.usersRepository.save(newUser);

I expect the fields in then record in the database to be snake case not camel case

Actual Behavior

firstName column is not mapped to first_name

Steps to Reproduce

Create an entity like the following and use the type orm MongoRepository to save a new record.

@Entity({ name: 'users' })
export class User {
   @ObjectIdColumn() readonly id: ObjectID;
   @Column({ name: "first_name" }) firstName: string;
}

Environment

Dependency Version
OS Windows 10
NodeJs 16.6.2
TypeORM 0.2.37
MongoDB 4.2

Crossposted from Github Issues

0 Answers
Related