How to fix mongoose type issue with ObjectID?

Solution for How to fix mongoose type issue with ObjectID?
is Given Below:

What is the current behavior?

I have an issue while building the node application on docker. It was building fine before but since last Friday ( 30/07/2021 ), I got the issues with mongodb. Building the application in my local environment is fine. The issue is just from the docker build.

image

Steps to reproduce.

I just run this command to build the app on docker:
docker-compose build && docker-compose up -d

docker-compose.yml

...
mongo:
    image: "mongo:4.2"
    ports:
      - "27017:27017"
    volumes:
      - ./data/mongo:/data/db
    restart: always
...

Dockerfile

FROM node:14
COPY . .
RUN npm install --production && npm run build
EXPOSE 3000
CMD ["npm", "start"]

tsbase.json

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "experimentalDecorators": true,
    "declaration": true,
    "target": "ES2017"
  }
}

tsconfig.json

{
  "extends": "./tsbase",
  "compilerOptions": {
    "outDir": "./dst"
  },
  "include": [
    "src/**/*"
  ]
}

What is the expected behavior?

It should build fine on docker.

What are the versions of Node.js, Mongoose, and MongoDB you are using? Note that “latest” is not a version.

Node 14

Mongoose ^4.11.8

MongoDB 4.2

@types/mongoose ^4.7.21

I found that mongo:4.2 image was updated 6 days ago on docker hub. In addition, I am on Mac

Can you please help me with this bug? Thank you.

I fixed the issue by adding @types/mongodb to my project.

Here’s the link for the details.