尝试使用带有stringify的$ set,但它不起作用

时间:2018-04-30 01:17:54

标签: javascript node.js mongodb express mongoose

我正在尝试使用此功能,在我的mongodb数据库中编辑一个空格,但我是新手,我不明白发生了什么。我在争论列表后得到错误。谢谢大家看到这个。

app.put('/factura/:id', (req, res) => {
    res.header({'Content-Type': 'application/json'});

    var factura = req.body;
    var facturaModel = new FacturaModel({
        nro: factura.nro,
        nit: factura.nit,
        cliente: factura.cliente,
        tarjeta: factura.tarjeta,
        detalles:[{producto: factura.nombre, cantidad: factura.cantidadSeleccionada, precio_unitario: factura.precio}]
    })

    FacturaModel.findByIdAndUpdate({id: req.params.id}, (err, factura) => {
        console.log(JSON.stringify(factura));
        res.end(JSON.stringify($set: factura));
    });


});

1 个答案:

答案 0 :(得分:0)

JSON.stringify接受对象作为参数。您尚未在那里创建对象,因此尝试将free声明为属性不起作用。如果你想要一个输出,如char *str = widen_stars(f, s); printf("The combined string is: %s\n", str); free(str); ,那么给JSON.stringify一个对象进行字符串化:

$set
相关问题