get one from mongodatabase using node js via api | nodejs tutorails

get one usng findone



app.get('/get-one-await',async (req, res)=> {
let params = req.query.id;
let listDetails= await PERSON_SCHEMA.findOne({id:params}).sort({_id:-1});
res.send(listDetails);
})

app.get('/get-by-id',async (req, res)=> {
let body = req.body;
PERSON_SCHEMA.find({fname: {$eq: body.name}}).then(result =>
{
res.send(result)
}).catch(err => {
res.send("faile")
})
})
app.get('/get-by-id-one',async (req, res)=> {
let body = req.body;
PERSON_SCHEMA.findOne({fname: {$eq: body.name}}).then(result =>
{
res.send(result)
}).catch(err => {
res.send("faile")
})
})

http://localhost:3000/get-by-id-one 


 







No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...