From 6b3b8c09496038797e0b3d0ffd8ad0b185cb64fa Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 29 May 2026 21:06:25 +0200 Subject: [PATCH] refactor(api): replace mongodb with bson (#67680) --- api/__fixtures__/exam-environment-exam.ts | 2 +- api/package.json | 2 +- api/src/routes/protected/user.test.ts | 2 +- api/src/routes/protected/user.ts | 2 +- api/src/routes/public/user.test.ts | 2 +- api/src/routes/public/user.ts | 2 +- api/src/utils/validation.ts | 2 +- pnpm-lock.yaml | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/api/__fixtures__/exam-environment-exam.ts b/api/__fixtures__/exam-environment-exam.ts index 6ff3b7c20b3..bf8877d8099 100644 --- a/api/__fixtures__/exam-environment-exam.ts +++ b/api/__fixtures__/exam-environment-exam.ts @@ -9,7 +9,7 @@ import { ExamEnvironmentQuestionSet, ExamEnvironmentChallenge } from '@prisma/client'; -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; import { examEnvironmentPostExamAttempt } from '../src/exam-environment/schemas/index.js'; const defaultUserId = '5bd30e0f1caf6ac3ddddddb5'; diff --git a/api/package.json b/api/package.json index 6bfc4c3c419..456c5cefaaa 100644 --- a/api/package.json +++ b/api/package.json @@ -17,6 +17,7 @@ "@sentry/node": "9.47.1", "ajv": "8.20.0", "ajv-formats": "3.0.1", + "bson": "7.2.0", "date-fns": "4.1.0", "date-fns-tz": "3.2.0", "dotenv": "16.6.1", @@ -27,7 +28,6 @@ "jsonwebtoken": "9.0.3", "lodash": "4.18.1", "lodash-es": "4.18.1", - "mongodb": "6.21.0", "nanoid": "3", "no-profanity": "1.5.1", "nodemailer": "6.10.1", diff --git a/api/src/routes/protected/user.test.ts b/api/src/routes/protected/user.test.ts index 3ce266fc603..963896aaa1f 100644 --- a/api/src/routes/protected/user.test.ts +++ b/api/src/routes/protected/user.test.ts @@ -14,7 +14,7 @@ import { } from 'vitest'; import jwt, { JwtPayload } from 'jsonwebtoken'; import { DailyCodingChallengeLanguage, type Prisma } from '@prisma/client'; -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; import { omit } from 'lodash-es'; import { createUserInput } from '../../utils/create-user.js'; diff --git a/api/src/routes/protected/user.ts b/api/src/routes/protected/user.ts index 31cb0e29138..3efe7258415 100644 --- a/api/src/routes/protected/user.ts +++ b/api/src/routes/protected/user.ts @@ -1,5 +1,5 @@ import type { FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'; -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; import { FastifyInstance, FastifyReply } from 'fastify'; import jwt from 'jsonwebtoken'; import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library.js'; diff --git a/api/src/routes/public/user.test.ts b/api/src/routes/public/user.test.ts index 40b457e4643..2eb4d198408 100644 --- a/api/src/routes/public/user.test.ts +++ b/api/src/routes/public/user.test.ts @@ -1,5 +1,5 @@ import type { Prisma } from '@prisma/client'; -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; import { omit } from 'lodash-es'; import { describe, diff --git a/api/src/routes/public/user.ts b/api/src/routes/public/user.ts index 423e911fefc..051d255daf8 100644 --- a/api/src/routes/public/user.ts +++ b/api/src/routes/public/user.ts @@ -1,6 +1,6 @@ import { Experience, Portfolio } from '@prisma/client'; import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'; -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; import { omit } from 'lodash-es'; import { isRestricted } from '../helpers/is-restricted.js'; diff --git a/api/src/utils/validation.ts b/api/src/utils/validation.ts index 87779595616..938a9df0d5e 100644 --- a/api/src/utils/validation.ts +++ b/api/src/utils/validation.ts @@ -1,4 +1,4 @@ -import { ObjectId } from 'mongodb'; +import { ObjectId } from 'bson'; // This is trivial, but makes it simple to refactor if we swap monogodb for // bson, say. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c734ba21ddf..2d5e46e1b01 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,6 +128,9 @@ importers: ajv-formats: specifier: 3.0.1 version: 3.0.1(ajv@8.20.0) + bson: + specifier: 7.2.0 + version: 7.2.0 date-fns: specifier: 4.1.0 version: 4.1.0 @@ -158,9 +161,6 @@ importers: lodash-es: specifier: 4.18.1 version: 4.18.1 - mongodb: - specifier: 6.21.0 - version: 6.21.0(@aws-sdk/credential-providers@3.521.0)(socks@2.8.7) nanoid: specifier: '3' version: 3.3.12