场景:我的NodeJS服务器上有一个端点来编辑订单文档上的退货地址。客户端和端点通信很好,当我通过控制台记录更新的订单文档时,地址甚至会更改,但它实际上从未保存在数据库中。以下是终结点:
const editShipsFromAddress = async (req, res) => {
const { orderId, address, country, city, state, zipcode } = req.body;
try {
const order = await Order.findById(orderId);
order.item.shipsFrom.address = address;
order.item.shipsFrom.country = country;
order.item.shipsFrom.state = state;
order.item.shipsFrom.city = city;
order.item.shipsFrom.zipcode = zipcode;
const savedOrder = await order.save();
console.log(savedOrder);
return res.json('Address updated');
} catch (err) {
console.log(err);
return res.status(500).json('Server error');
}
};
所有订单都以order.Item作为空Obj开头。
1条答案
按热度按时间ssm49v7z1#
例如: