express+mongodb,两个数据模型关联的时候出错了
两个数据模型关联的时候出错了,不知道问题出在那里,望解答。谢谢 alt text alt text
25 回复
贴上一部分你的代码,你不觉得有问题么 newUser: async (req, res, next) => { try { const newUser = new User(req.body); const user = await newUser.save(); res.status(201).json(user); } catch (err) { next(err); } }
@CodeofGame 恩,果然是那样,不过我还是没理解到。 我typeof了下 console.log(‘typeof newCar’, typeof newCar); ==>object console.log(‘typeof newCar.toObject’, typeof (newCar.toObject()));==>object 都是object
https://github.com/Automattic/mongoose/issues/1961#event-242694964 你可以看下这个issues,目测是mongoose的一个坑 image.png