I am working on a NestJS Project that is based on micro-service architecture (Kafka, CQRS Patter).
I have created a shared mongodb database inside docker container and exposed the port to 8081 Port which is accessible via browser(I am using mongo-express ui). Here is the docker-compose.yml file
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: PWD
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
volumes:
- data-volume:/data/db
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: PWD
volumes:
data-volume:
And in my NESTJS Service, I have defined mongo connection like this: (app.module.ts)
import { Module } from '@nestjs/common';
import { APP_FILTER } from '@nestjs/core';
import { CqrsModule } from '@nestjs/cqrs';
import { MongooseModule } from '@nestjs/mongoose';
import { UserModule } from './user/user.module';
@Module({
imports: [UserModule, MongooseModule.forRoot('mongodb://localhost:8081/urooj', {
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true
})],
controllers: []
})
export class AppModule {}
And in my user module I am defining User schema: (user.module.ts)
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { UserController } from './user.controller';
import { UserHandler } from "./command/handler/index";
import { MongooseModule } from '@nestjs/mongoose';
import { UserSchema } from './models/user.model';
import { UsersRepository } from './user.repository';
import { UserService } from './user.service';
@Module({
imports: [
CqrsModule,
MongooseModule.forFeature([{name: 'User', schema: UserSchema}])
],
controllers: [UserController],
providers: [
...UserHandler,
UserService
]
})
export class UserModule {}
But I am getting this error which I tried finding the solution but i am bit unlucky in solving this issue from quite sometime now.
events.js:292
throw er; // Unhandled 'error' event
^
MongoParseError: Invalid message size: 1347703880, max allowed: 67108864
at processIncomingData (/Users/rk/Desktop/workspace/project/service/node_modules/mongodb/lib/cmap/message_stream.js:118:7)
at MessageStream._write (/Users/rk/Desktop/workspace/project/service/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at doWrite (_stream_writable.js:403:12)
at writeOrBuffer (_stream_writable.js:387:5)
at MessageStream.Writable.write (_stream_writable.js:318:11)
at Socket.ondata (_stream_readable.js:716:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at Socket.Readable.push (_stream_readable.js:212:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on MessageStream instance at:
at errorOrDestroy (internal/streams/destroy.js:108:12)
at MessageStream.onerror (_stream_readable.js:752:7)
at MessageStream.emit (events.js:315:20)
at errorOrDestroy (internal/streams/destroy.js:108:12)
at onwriteError (_stream_writable.js:418:5)
at onwrite (_stream_writable.js:445:5)
at processIncomingData (/Users/rk/Desktop/workspace/project/service/node_modules/mongodb/lib/cmap/message_stream.js:117:5)
at MessageStream._write (/Users/rk/Desktop/workspace/project/service/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
[... lines matching original stack trace ...]
at Socket.Readable.push (_stream_readable.js:212:10)
Thank you for the help in advance.
I fixed this above issue by Exposing Port to mongo service in my docker-compose.yml apart from mongo-express service.
But I ran into another issue now and that is related to authentication when connecting to mongodb using nestjs. Though Mongodb Container can be accessed using compass. I will be debugging this and if required will raise a new question in SO.