Ich möchte eine Abstimmung App machen, ich habe ein Schema namens Poll. im Poll-Schema habe ich ein "Optionen" -Objekt. ich möchte die options.vote nach id aktualisieren. wie ich zu Poll (id) .options (id) .vote aufrufen? , dass mein Versuch:Mongoose Und mongodb findById mit Objekt in Objekt
app.post("/:id/:option_id", function(req, res){
Poll.findById(req.params.id,function(err, poll){
if(err){
console.log("Vote(find the Poll) post err");
} else{
poll.options.findById(req.params.option_id,function(err,option){
if(err){
console.log("Vote(find the option) post err");
} else{
option.vote++;
option.vote.save(function(err){
if(err){
console.log("save vote error");
} else{
res.redirect("/:id/:option_id");
}
});
}});
}
Sie wollen '.findOne()' als '.findById()' ist "strikt" eine Alias-Verknüpfung für '.findOne ({" _id ": id})'. Das ist alles, wofür es ist. Sie möchten etwas anderes, dann verwenden Sie stattdessen die vollständige Methode. –