动态更新猫鼬中的密钥

时间:2020-01-11 00:38:30

标签: node.js

因此,我希望能够动态更新我的mongoDB数据库,并且由于某种原因,我无法将值设置为我得到的req.body的键。

下面的代码显示Find()而不是Update(),但是当我弄清楚如何动态设置值时,我将对其进行更改

  app.post('/upload', upload.single('photo'), (req, res, err) => {

    if (req.file) {

    var query = {};

    query["index"] = req.body.imageindex;

    Image.find(query, function(err, found){
        console.log(found);
    })
};
res.redirect("/")

现在,如果我将“ req.body.imageindex”更改为简单的1(不是字符串),则可以正常工作,并且它会在console.log(找到)中返回一个对象,但是当我有req.body时不会。指数。有什么办法或原因吗?

});

更新:现在可以通过使用以下代码来工作:

   if (req.file) {

    var index = JSON.parse(req.body.imageindex, null, ' ')
    var query = {index: index};
    console.log();

    Image.find(query, function(err, found){
        console.log(found);

    })
};
res.redirect("/")

0 个答案:

没有答案