Skip to content

Commit

Permalink
add writing indexes to mongodb on app start
Browse files Browse the repository at this point in the history
  • Loading branch information
dotFionn committed Mar 24, 2024
1 parent 83541fc commit b22f55e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import cookieParser from 'cookie-parser';
import { Request } from 'express';
import mongoose from 'mongoose';
import morgan from 'morgan';
import { WinstonModule } from 'nest-winston';

Expand Down Expand Up @@ -37,6 +38,14 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

(async () => {
try {
await mongoose.syncIndexes();
logger.info('Synced indexes to MongoDB!');
} catch (error) {
logger.warn('Failed to sync indexes to MongoDB: %o', error);
}
})();

await app.listen(3000);
}
Expand Down

0 comments on commit b22f55e

Please sign in to comment.