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.
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
firstName column is not mapped to first_name
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;
}
| Dependency | Version |
|---|---|
| OS | Windows 10 |
| NodeJs | 16.6.2 |
| TypeORM | 0.2.37 |
| MongoDB | 4.2 |