From 71bac76c3abf971a038a27d7a72b4c4a3538e928 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Mon, 23 Sep 2024 00:04:06 +0100 Subject: [PATCH] More mongodb migration bugs, remove _id from find, and a stat endpoint firebase leftover bug --- src/pages/api/stats/[id]/index.ts | 2 +- src/utils/users.be.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pages/api/stats/[id]/index.ts b/src/pages/api/stats/[id]/index.ts index f531284b..75cd2f41 100644 --- a/src/pages/api/stats/[id]/index.ts +++ b/src/pages/api/stats/[id]/index.ts @@ -16,5 +16,5 @@ async function GET(req: NextApiRequest, res: NextApiResponse) { const snapshot = await db.collection("stats").findOne({ id: id as string}); if (!snapshot) return res.status(404).json({id: id as string}); - res.status(200).json({...snapshot.data(), id: snapshot.id}); + res.status(200).json({...snapshot, id: snapshot.id}); } diff --git a/src/utils/users.be.ts b/src/utils/users.be.ts index cd5c1c1a..31ecbe05 100644 --- a/src/utils/users.be.ts +++ b/src/utils/users.be.ts @@ -8,11 +8,11 @@ import client from "@/lib/mongodb"; const db = client.db(process.env.MONGODB_DB); export async function getUsers() { - return await db.collection("users").find({}).toArray(); + return await db.collection("users").find({}, { projection: { _id: 0 } }).toArray(); } export async function getUser(id: string): Promise { - const user = await db.collection("users").findOne({id}); + const user = await db.collection("users").findOne({id: id}, { projection: { _id: 0 } }); return !!user ? user : undefined; } @@ -21,7 +21,7 @@ export async function getSpecificUsers(ids: string[]) { return await db .collection("users") - .find({id: {$in: ids}}) + .find({id: {$in: ids}}, { projection: { _id: 0 } }) .toArray(); }