-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
41 lines (31 loc) · 900 Bytes
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const express = require('express');
const dbConnect = require('./Monogodb');
const Monogodb = require('mongodb');
const app=express();
app.use(express.json());
app.get('/',async (req,resp)=>{
let data = await dbConnect();
data = await data.find().toArray();
resp.send(data);
})
app.post('/',async (req,resp)=>{
let data = await dbConnect();
const result = await data.insertMany(req.body);
console.log(result);
resp.send(result);
})
app.put('/:name',async (req,resp)=>{
let data = await dbConnect();
let result = data.updateMany(
{name:req.params.name},
{$set:req.body}
)
resp.send(result);
})
app.delete('/:id',async (req,resp)=>{
let data = await dbConnect();
const result = await data.deleteOne({_id: new Monogodb.ObjectId(req.params.id)})
console.log(req.params.id);
resp.send(result);
})
app.listen(4500);