#When importing a mongodb schema in a module, the service cannot start

1 messages · Page 1 of 1 (latest)

opal ivy
#

Stuck in the middle and No errors reported

// mongodb connection

import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';

@Module({
    imports: [
        MongooseModule.forRootAsync({
            useFactory: () => ({
                uri: `mongodb://${process.env.MONGODB_SERVER}:${process.env.MONGODB_PORT}`,
                dbName: process.env.MONGODB_DBNAME,
            }),
        }),
    ],
    exports: [],
})
export class MongodbModule {}
// schema
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
export type ListDocument = List & Document;
@Schema()
export class List extends Document {
    @Prop({ default: '' })
    notes: string;
}
export const ListSchema = SchemaFactory.createForClass(List);
// list module
import { Module } from '@nestjs/common';
import { TestService } from './test.service';
import { TestController } from './test.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { List, ListSchema } from 'src/database/mongodb/schema/list.schema';
@Module({
    imports: [MongooseModule.forFeature([{ name: List.name, schema: ListSchema }])],
    controllers: [TestController],
    providers: [TestService],
})
export class TestModule {}
// service
import { Injectable } from '@nestjs/common';

@Injectable()
export class TestService {}
// controller
import { Controller } from '@nestjs/common';
import { TestService } from './test.service';

@Controller('test')
export class TestController {
  constructor(private readonly testService: TestService) {}
}
drifting plover
#

No error at all? What do the logs look like at boot-up?

opal ivy
#

not error log , this is logs ```
[Nest] 3752 - 2023/07/25 16:04:16 LOG [NestFactory] Starting Nest application...
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] MongodbModule dependencies initialized +32ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] MongooseModule dependencies initialized +1ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] TaskModule dependencies initialized +9ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] RedisModule dependencies initialized +1ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] JwtModule dependencies initialized +0ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] DiscoveryModule dependencies initialized +0ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] AuthModule dependencies initialized +1ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] ScheduleModule dependencies initialized +1ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] UserModule dependencies initialized +0ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] EventModule dependencies initialized +0ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] AppModule dependencies initialized +1ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] MongooseCoreModule dependencies initialized +14ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] MongooseModule dependencies initialized +5ms
[Nest] 3752 - 2023/07/25 16:04:17 LOG [InstanceLoader] ListModule dependencies initialized +2ms

#

When I wrote this line of code in the service, everything was normal ```
constructor() {
console.log(213);
}

drifting plover
#

I have no idea what might be the issue. But, it might be you just don't have enough meat on the bone (no working code in TestService) to get Nest to boot up properly. Don't quote me on that though. You might try changing logger to verbose. That might give you more info. Not sure about that ether. https://docs.nestjs.com/techniques/logger

opal ivy
#

This app occasionally starts normally, but most of the time it gets stuck in the middle of startup

drifting plover
#

Hmm... no clue. Maybe someone else has a better idea. Sorry I'm of little help.