暂停POST表单来更新MongoDB中的文档

Stall POST form to update documents in MongoDB

本文关键字:文档 MongoDB 更新 POST 表单 暂停      更新时间:2023-09-26

所以基本的想法是暂停POST表单,这样我就可以收集更多的数据。

当前:我正在开发一个应用程序,以加快对某些视图的测试。因此,我通过HTML画布元素呈现一个视图,用户通过表单对视图进行投票并点击提交,然后将表单作为文档发送给MongoDB。然后页面刷新,我知道这是最佳实践。

然而,在这个应用程序中,我想循环遍历几个视图,以便用户可以测试多个视图。理想情况下,每次用户提交表单时,都会使用用户的结果更新Mongo文档,并通过函数调用呈现新视图,直到调用最后一个视图,但这受到了阻碍,因为我不太确定如何处理响应。

我的形式。玉文件:

block content
    .container
        .well
            form.form-horizontal(name="resultSubmit" method="post" action="/create")
                fieldset
                    legend PDF Metrology
                    .form-group
                        label.col-md-2.control-label(for="Name") Name
                        .col-md-10
                            input#Name(name="Name" value=name type="text" placeholder="John Smith" required).form-control.input-lg
                    .form-group
                        label.col-md-2.control-label(for="selectbasic") Select One
                        .col-md-10
                            select#selectbasic(name="better_pdf").form-control
                                option(value=-2) U is much better than S
                                option(value=-1) U is better than S
                                option(value=0) U is the same as S
                                option(value=1) S is better than U
                                option(value=2) S is much better than U
                    .form-group
                        label.col-md-2.control-label(for="printS") Is S good enough to print?
                        .col-md-10
                            label.radio-inline(for="radios-1")
                                input#radios-1(type="radio" name="printS" value=1 checked="checked")
                                | Yes
                            label.radio-inline(for="radios-0")
                                input#radios-0(type="radio" name="printS" value=0)
                                | No
                    .form-group
                        .col-md-10.col-md-offset-2
                        .pull-right
                            button(type="submit").btn.btn-primary Submit

我的表单处理post是通过一个app.js文件使用的

/* POST form */
router.post('/', function(req,res) {
    console.log(req.body);
    MongoClient.connect(url, function (err, db) {
        assert.equal(null,err);
        console.log(req.body);
        var collection = db.collection('pdf_models');
        var doc = req.body;
        collection.insertOne(doc, function(err, result) {
            assert.equal(err,null);
            console.log("Inserted a document: " + JSON.stringify(doc));
            db.close();
        });
    });
    res.send('It worked!');
}); 

应该是

router.post('/create', function(req,res)