Spaces:
Running
Running
| // Next.js API route support: https://nextjs.org/docs/api-routes/introduction | |
| import type { NextApiRequest, NextApiResponse } from "next"; | |
| import { API } from "utils/api"; | |
| import clientPromise from "lib/mongo"; | |
| export default async function handler( | |
| req: NextApiRequest, | |
| res: NextApiResponse | |
| ) { | |
| const client = await clientPromise; | |
| const db = client.db("test"); | |
| const getCount = await db.collection("icons").findOne({ | |
| counter: true, | |
| }); | |
| await db.collection("icons").updateOne( | |
| { | |
| counter: true, | |
| }, | |
| { | |
| $set: { | |
| amount: getCount.amount + 1, | |
| }, | |
| } | |
| ); | |
| res.status(200); | |
| } | |