-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.js
43 lines (37 loc) · 1.32 KB
/
data.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
42
43
const express=require('express')
const mongoose=require("mongoose");
const cors=require("cors");
const app=express();
app.use(cors());
app.use(express.json());
{/*mongoose.connect('mongodb://localhost:27017/Student',{
useNewUrlParser:true,
useUnifiedTopology:true,
})*/}//this is for insert data into database
app.post('/message',(req,res)=>{
const receivedData=req.body;
console.log('data received on Express',receivedData.password,receivedData.username);
//res.json({message:'data send successfully!'})
const UserSchema=new mongoose.Schema({
username:String,
password:String
})
const studetails=mongoose.model("studetails",UserSchema)
const stud=new studetails(receivedData);
stud.save().then(
()=>console.log("one entry added"),
(err)=>console.log(err),
);//this for insert data into database
const UserModel=mongoose.model("studentdetails",UserSchema)
module.exports=UserModel,
mongoose.connect("mongodb://localhost:27017/Student")
UserModel.find({},{_id:0,password:1})
.where("username")
.equals(receivedData.username)
//.where("password")
//.equals(receivedData.password)
.then(users=>res.send(users))
.catch(err=>res.json(err))
//res.send({message:'success'})
});
app.listen(3300,()=>console.log("server is up"))