【发布时间】:2015-02-21 13:44:15
【问题描述】:
我对 Node.js 和 MongoDB 还是很陌生。我正在尝试使用此代码,其中我有一个名为 test 的布尔文档,该文档在 Mongodb 中最初为“假”,我想在加载页面 /hello 时提醒这一点。然后转到另一个页面提交表单并将 test 更新为 true 并再次加载 /hello。所以这一次它应该提醒真实(当我检查数据库时它已经更新为真实)但是当我测试它时它不会提醒任何东西。如果你让我知道什么时候做错了,那就太好了!
这是我的 app.js 中的相关代码
app.post("/Submitted", function(req,res){
var conditions = mongoose.model('users').findOne({username: req.session.user.username}, function (err, doc){
doc.test = true;
doc.save();
res.redirect('hello');
});
app.get('/hello', function (req, res) {
var umbrella = req.session.user.test;
if (req.session.user) {
res.render('5points', {test: test});
} else {
res.redirect('/');
}
});
这是我的玉文件:
script.
function check() {
var test= !{JSON.stringify(test)};
alert(test);
body(onload= "check()")
【问题讨论】:
标签: node.js mongodb express mongoose