We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using column aliases with MongoDB, TypeORM does not use the alias when inserting/updating records, it only uses it when querying data.
When declaring a class like so
@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 so
MongoRepository
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
firstName
first_name
Create an entity like the following and use the type orm MongoRepository to save a new record.
None
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
The text was updated successfully, but these errors were encountered:
Any update on this issue @glister ?
Getting the same issue with my project.
@imnotjames any idea ? Same result with MongoRepository.
Sorry, something went wrong.
But it works for auto-generated columns (properties) like 'CreateDateColumn' & 'UpdateDateColumn'.
import { Column, CreateDateColumn, Entity, ObjectIdColumn, UpdateDateColumn } from 'typeorm'; import { ObjectId } from 'mongodb'; @Entity() export class User { @ObjectIdColumn() id: ObjectId; @Column({ unique: true, name: 'provider_id', nullable: true }) providerId?: string; @Column() displayName: string; @Column() email: string; @Column({ name: 'avatar_url' }) avatarUrl: string; @Column({ nullable: true }) projects?: Array<ObjectId>; @Column({ nullable: true }) teams?: Array<ObjectId>; @CreateDateColumn({ name: 'created_at', type: 'time with time zone' }) createdAt: Date; @UpdateDateColumn({ name: 'updated_at', type: 'time with time zone' }) updatedAt: Date; }
tss2-dev> db.user.find({}) [ { _id: ObjectId("61cd7b4abc2f0f654b960739"), providerId: 'well... this is censored', displayName: 'Krishna', email: 'akrishnamoorthy007@gmail.com', avatarUrl: 'also this', created_at: ISODate("2021-12-30T09:26:34.134Z"), updated_at: ISODate("2021-12-30T09:26:34.134Z") } ]
No branches or pull requests
Issue Description
When using column aliases with MongoDB, TypeORM does not use the alias when inserting/updating records, it only uses it when querying data.
Expected Behavior
When declaring a class like so
and inserting a new record with a
MongoRepository
like soI expect the fields in then record in the database to be snake case not camel case
Actual Behavior
firstName
column is not mapped tofirst_name
Steps to Reproduce
Create an entity like the following and use the type orm MongoRepository to save a new record.
My Environment
Additional Context
None
Relevant Database Driver(s)
aurora-data-api
aurora-data-api-pg
better-sqlite3
cockroachdb
cordova
expo
mongodb
mysql
nativescript
oracle
postgres
react-native
sap
sqlite
sqlite-abstract
sqljs
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: