mongodb connection

This commit is contained in:
isaconantonis 2023-07-12 15:47:01 +02:00
parent 2bc3453ff9
commit ee267bf62a
20 changed files with 210 additions and 548 deletions

16
pages/api/players.ts Normal file
View file

@ -0,0 +1,16 @@
import client from "../../lib/mongodb"
export default async function handler(req, res) {
const db = client.db("SloppyFuckers")
switch (req.method) {
case "POST":
let bodyObject = JSON.parse(req.body)
let myPost = await db.collection("players").insertOne(bodyObject)
res.json(myPost.ops[0])
break
case "GET":
const allPosts = await db.collection("players").find({}).toArray()
res.json({ status: 200, data: allPosts })
break
}
}