这是我的控制器代码 我想通过其ID更新地址对象,而我的mongodb集合名称是具有数组对象地址的用户。
This is my user model details where I want to update the object by it's id
exports.updateAddressObject = (req, res) => {
let address = []
address.push({
fullname: req.body.fullname,
country: req.body.country,
streetnumber: req.body.streetnumber,
apartment: req.body.apartment,
city: req.body.city,
region: req.body.region,
pincode: req.body.pincode,
phone: req.body.phone,
landmark: req.body.landmark
})
User.findOne({'_id': req.params.userId,'address': {'_id':req.params.addressId}},
{ $push: { address: address } },
{ 'new': true },
(error, data) => {
if (error) {
return res.status(400).json({
error: "Could not update user's new Address"
});
}
res.json(data)
}
)
};