I'm trying to create an IOT device where it sends geographic data(coordinates) in real time. I have create a server using Nodejs,express,mongoose . I need to check if coordinate exist while saving the coordinated data. It means when i save the coordinate data it should send True or False as response if the coordinates exist in the database. Any idea on how to achieve this? Here is what i have tried but it take 2 calls to retrieve the data. I need to save the record as well getting the true/false response from saving the data.
geo.create({
package:req.body.package,
longitude: req.body.longitude,
lattitude: req.body.lattitude},
function(err,data){
if (err) throw err;
geo.find({longitude: req.body.longitude,lattitude: req.body.lattitude})
.then((data)=>{
res.send("true");
})
.catch((err)=>{
console.log(err);
})
});