繁体   English   中英

html提交为变量字段表达式mongodb

[英]html submit as variable field expression mongodb

我想将 html 表单字段的输出集成为我的 mongodb 查询中的变量。 “Kalenderwoche”功能的特性应相应调整。

我的表单 html 代码是:

 <div>
                <form action="/index" method="POST" class="k_week">
                    <Label>
                        <input type="text" id="k_week" name="k_week">
                        <input type="submit" id="sub_k_week" value="go" placeholder="1">
                        
                    </Label>
                </form>
            </div>

我的基于 node.js 的脚本是:

app.post("/index", (req, res)=>{
let num_k_week=req.body.k_week;

console.log(num_k_week);
const mongoDB = require('mongodb');
const client = require('mongodb').MongoClient;
const url = 'mongodb://localhost:27017/vertrieb';
client.connect(url, (error,db) => {
    if (!error){
        console.log("Verbindung steht");
                };
                let col = db.collection("umsatz5");
                console.log(num_k_week)
                col.aggregate([{'$match': {'AD': 'Bart Simpson'}}, {'$match': {'Kalenderwoche':'2'}}, {'$group': {'_id': null, 'UTom': {'$sum': '$Umsatznetto'}}}], function(err, result){
                    if (err) {
                        console.error("Error calling", err);
                    }

                    console.log(result[0].UTom);
                    U_Tom_week  = result[0].UTom;
                

                });
                db.close()
            });

});

我现在想将特征“日历周”的值“ 2”设计为变量。

{'$match': {'Kalenderwoche':'2'}}

目的是当通过表单选择日历周时,会进行相应的计算。我将不胜感激任何有关实施的建议或帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM