无法从前端到后端获取数据,以便通过使用Express更新我的mongoDB



我的。hbs是否运行在localhost:8001/docconfirm(使用hadlebars/Template Engine)

<form id="login" method="GET" action="#">
<div class="form-group">
<label>Doctor's Email<span class="req">*</span> </label>
<input type="email" name="das" class="form-control" id="email" required data-validation-required-message="Please enter your email address." autocomplete="off">
<p class="help-block text-danger"></p>
</div>
<br>
<div>
<h5 style="color:rgba(0, 255, 255, 0.588);">Choose an Updation Field:</h5>
<select name="egyarah" class="form-control" id="Practice" >
<option value="First_Name">First-Name</option>
<option value="Last_Name">Last-Name</option>
<option value="Image">Image</option>
<option value="Email">Email</option>
<option value="Description">Job-Description</option>
</select>
</div>
<br>
<div class="form-group">
<label> Enter the detail to be updated<span class="req">*</span> </label>
<textarea name="baarah" class="form-control" style="color:rgb(255, 255, 255);" required data-validation-required-message="Please enter meet-up address."></textarea>
<p class="help-block text-danger"></p>
</div>
<div class="mrgn-30-top">
<button type="submit" class="btn btn-larger btn-block"/>
Update Profile
</button>
</div>
</form>

我的后端快递代码是:

app.put("/docconfirm/:das", (req, res) => {
console.log("heyyy");
Handles.findOneAndUpdate(
{Email:req.params.das},//trying to fetch the data got in URL and search it on my DB
{Description: String("mm")},// trying to update it after when the search is done
{new: true},//helps me printing the updated values
function(err,doc){
console.log(doc)// :( Not Working please help :)
})
});

——比;我想从前端获取数据我想通过前端的输入更新数据库但它不工作

my Schema is this - Using MongoDB(Mongoose)

const mongoose =require("mongoose");
mongoose.connect("mongodb://localhost:27017/Youraid",{useNewUrlParser: true,useUnifiedTopology:true}).then(()=>console.log("got connected from confirmdoc")).catch((err)=>console.log(err));
//creating schema for the database that has been connected by using the above code
const expSchema=new mongoose.Schema({
First_Name:{
type: String,
//required: true
},
Last_Name:{
type: String,
//required: true
},
Email:{
type: String,
unique: true,
//required: true
},
Image:{
type: String,
//required: true
},
Description:{
type: String,
//required: true
}


})
const Datass= new mongoose.model("docconfirm",expSchema);

module.exports = Datass;

提交<form>会产生类似GET http://localhost:8001/docconfirm?das=x.y@z.com&egyarah=Email&baarah=meetup-address#的请求。要在服务器上处理它,需要像

这样的内容
app.get("/docconfirm", function(req, res) {  // get, not put, no :das parameter
Handles.findOneAndUpdate(
{Email:req.query.das},  // req.query, not req.params
{Description: String("mm")},
{new: true},
function(err, doc) {...});
});

最新更新