为了账号安全,请及时绑定邮箱和手机立即绑定

mongoose报错Cast to ObjectId failed for value "{ id: '58c41d5d3eddd93e9ab5b078' }" at path "_id"

/ 猿问

mongoose报错Cast to ObjectId failed for value "{ id: '58c41d5d3eddd93e9ab5b078' }" at path "_id"

慕慕6433607 2018-06-29 15:43:00

用mondoose  往数据库添加数据的时候报 Cast to ObjectId failed for value "{ id: '58c41d5d3eddd93e9ab5b078' }" at path "_id" 的错误 什么原因呢?

https://img3.mukewang.com/5b35e2e200011ecd05270340.jpg

报错内容:

User validation failed: _id: Cast to ObjectId failed for value "{ id: '58c41d5d3eddd93e9ab5b078' }" at path "_id", cartList.4._id: Cast to ObjectId failed for value "{ id: '58e704ef98dab115d336b3f1' }" at path "_id", cartList.3._id: Cast to ObjectId failed for value "{ id: '58c284e6117a2e6599abef5f' }" at path "_id", cartList.2._id: Cast to ObjectId failed for value "{ id: '58e7051698dab115d336b3f4' }" at path "_id", cartList.1._id: Cast to ObjectId failed for value "{ id: '58c284f4117a2e6599abef60' }" at path "_id", cartList.0._id: Cast to ObjectId failed for value "{ id: '58e7058498dab115d336b3fc' }" at path "_id"

查看完整描述

3 回答

?
小王子loving

字段_id是字符串类型,修改为ObjectId类型即可 

将原来mongovue中的"_id":"58c41d5d3eddd93e9ab5b078"

修改为

"_id":ObjectId("58c41d5d3eddd93e9ab5b078")  试试!

查看完整回答
反对 回复 2019-06-11
?
慕慕6433607

https://img1.mukewang.com/5b35e5340001c38802300108.jpg

这是我上传额数据


查看完整回答
反对 回复 2018-06-29
?
慕慕6433607

https://img1.mukewang.com/5b35e5090001ada104570465.jpg

这是数据库上的数据

查看完整回答
反对 回复 2018-06-29

添加回答

回复

举报

0/150
提交
取消
意见反馈 邀请有奖 帮助中心 APP下载
官方微信