Closed audriuiv closed 2 years ago
Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).
Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.
Is there an existing issue for this?
Current behavior
Aliases in schemas don't work.
Mongo document ` { "_id" : ObjectId("5bd6ff5ea392f7302f26c906"), "limit" : 3, "filter" : { "where" : [ [ { "column" : "is_disabled", "operator" : "$eq", "value" : "0", "is_eval" : false } ] ], "by" : [ [ "AccountStatistic", "item_amount", "DESC" ] ], "limit" : 0 }, "architecture" : [ { "select" : [ [ { "column" : "item_amount", "operator" : ">=", "value" : 3 } ] ], "items" : { "filter" : { "where" : [ [ { "column" : "created_at", "operator" : "gte", "value" : "Sequelize.literal('DATE_SUB(CURDATE(), INTERVAL 30 DAY)')", "is_eval" : true } ] ], "by" : [ [ "all_reads", "DESC" ] ], "limit" : 1 } }, "assets" : [ { "type" : "column", "assets" : [ { "tag" : "account_img", "style" : { "margin" : "0" }, "link" : { "is_show" : true, "second_slug" : "" }, "assets" : [ ] }, { "style" : {
} `
Minimized Schema only for two fields:
` @Schema({ collection: 'accounts_slideshow' }) export class AccountSlideshow extends Document { @Prop({ alias: 'limit', type: Number}) limit2: number
//@Prop({ type: SchemaFactory.createForClass(Filter), ref: () => Filter }) // filter2: Filter
// @Prop({ type: [ArchitectureItemSchema] }) // architecture: ArchitectureItem[]
@Prop({ alias: 'position' }) position2: string } export type AccountSlideshowDocument = AccountSlideshow & Document
export const AccountSlideshowSchema = SchemaFactory.createForClass(AccountSlideshow) `
Repository:
` import { Injectable } from '@nestjs/common' import { InjectModel } from '@nestjs/mongoose' import { Model } from 'mongoose' import { AccountSlideshow, AccountSlideshowDocument, } from 'schemas/account.slideshow'
@Injectable() export class AccountSlideshowsRepository { constructor( @InjectModel(AccountSlideshow.name) private readonly _slideshowModel: Model,
) {}
public async find(): Promise {
const res = this._slideshowModel.findOne()
return await res.exec()
}
}
`
Nestjs module:
@Module({ imports: [ MongooseModule.forFeature([ { name: AccountSlideshow.name, schema: AccountSlideshowSchema }, ]), SequelizeModule.forFeature([Account, Item]), ], providers: [ AccountSlideshowsRepository, AccountsRepository, AccountSlideService, AccountHandler, ItemsRepository, ], controllers: [AccountSlideController], }) export class AccountSlideModule {}
Service
` @Injectable() export class AccountSlideService { constructor( private readonly _slidesRepository: AccountSlideshowsRepository, private readonly _accountHandler: AccountHandler, ) {}
public async getAccounts(offset: number): Promise {
const settings = await this._slidesRepository.find()
console.log(settings) // works and gets plain JavaScript object from Mongo db
console.log(settings.limit2) - undefined
console.log(settings.position2) - undefined
}
}
`
I get data from Mongo db. There is not errors. But aliases don't work. I know, this is a bug.
Minimum reproduction code
https://github.com
Steps to reproduce
No response
Expected behavior
console.log(settings.limit2) // --> 3
Package version
8.1.3
mongoose version
6.0.9
NestJS version
8.1.3
Node.js version
14.17.6
In which operating systems have you tested?
Other
No response