mongodb connection
This commit is contained in:
parent
2bc3453ff9
commit
ee267bf62a
20 changed files with 210 additions and 548 deletions
16
pages/api/players.ts
Normal file
16
pages/api/players.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue