I have following HTML form
<form id="contact-form" method="POST" action="/search">
<label for="company">Phone company</label>
<input type="text" name="company" value="">
<br>
<label for="modelname">Model name</label>
<input type="text" name="modelname" value="">
<br>
<label for="numbername">Model number</label>
<input type="text" name="numbername" value="">
<br>
<input type="submit" value="Search">
</form>
Phone schema
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const phoneSchema = new Schema({
company: String,
modelname: String,
numbername: String,
picture: String,
price: String,
});
const Phone = mongoose.model('phone', phoneSchema);
module.exports = Phone;
For example,I have next phone in my database:
{
"_id" : ObjectId("5b155a66aced9b079c276ba0"),
"company" : "Samsung",
"modelname" : "Galaxy",
"numbername" : "S5",
"picture" : "https://drop.ndtv.com/TECH/product_database/images/2252014124325AM_635_samsung_galaxy_s5.jpeg",
"price" : "12500P",
"__v" : 0
}
Post request handler
app.post('/search', urlencodedParser, function(req, res){
console.log(req.body);
Phone.findOne({company: req.body.company, modelname: req.body.modelname, numbername: req.body.numbername}).then(function(){
.......
})});
If company,modelname,numbername in this form are same with same database fields then I have to render page with all info from database( company + picture + price for example).How I can compare form data and database data?