I’ve got a nest.js project with mongodb and typeorm.
There is a method that loads all records from a mongo document (there are <10 records). I do it, roughly, like this:
@Injectable()
export class MyService {
public constructor(
@InjectRepository(MyEntity)
private readonly myEntity: Repository<MyEntity>
) {}
public loadAllRecords() {
return this.myEntity.find();
}
}
Simplified entity:
@Entity({ name: 'my_entity' })
export class MyEntity {
@PrimaryColumn({
type: 'varchar',
length: 50,
name: '_id',
})
@ObjectIdColumn({
type: 'varchar',
length: 50,
name: '_id',
})
public alias: string;
@Column({
type: 'varchar',
length: 100,
unique: true,
nullable: false,
name: 'default_name',
})
public defaultName: string;
}
In other places similar code works perfectly. In this particular place typeorm loads correct raw data (I’ve logged and checked it), but then it puts only the alias
in the created entity instance. Pay attention, it doesn’t set a default_name
property, it doesn’t set any properties, aside from the alias
at all. So, the metadata works, since _id
is correctly parsed into alias
, the data extraction works, there must be something wrong with the transformation. Metadata of the other columns, other than alias
, seems fine, but maybe you’d tell me which exact properties to check.
There are no reported bugs like this one (at least I haven’t been able to find them). Most likely, nobody can tell me what is wrong exactly, so the question I ask is this: which JS files from the typeorm in the node_modules
folder can I use to add console.log
s to see how the raw DB data is handled to create entity instances? So I would be able to see why the rest of the properties are skipped.