验证失败:video_data.0._id:路径 \"_ 处的值 \ ""(类型字符串)强制转换为 ObjectId 失败



im构建React表单时,当我从React发出post请求时,im获取错误消息验证失败:video_data.0。id:Cast to ObjectId for value失败"quot;(类型字符串(在路径"处.这里我通过console.log(JSON.stringfy(booksStore(+";数据hhhhhhhh"(像这样。这里使用两个动态表格。我如何解决这个问题?请指导我

{
"book_rating_count":22,
"book_review":0,
"book_like":0,
"_id":"61b6f8a3ba3b7a3d10d0afe0",
"book_title":"dgfgh",
"book_authore":"uytiu",
"book_overview":"fghfjhhg",
"book_category":"jhk",
"book_genre":"Trending Now",
"book_tag":"comedy",
"book_languages":"uii",
"book_duration":"uiuy",
"book_rating":5,
"book_publication":"gyhrt",
"booksEpdf":"https://booksepdf.s3.amazonaws.com/Screenshot%20%28166%29.png",
"booksAudio":"https://booksaudioes.s3.amazonaws.com/Screenshot%20%28166%29.png",
"video_data":[
{
"_id":"61b6f8a3ba3b7a3d10d0afe1",
"number_of_chapters":1,
"video_title":"ghhghggg",
"description":"ghghg",
"booksVideo":"https://hashvideo.s3.ap-south-1.amazonaws.com/Screenshot%20%28166%29.png",
"booksImage":"https://bookstoreimage.s3.amazonaws.com/Screenshot%20%28166%29.png",
"releaseDate":null,
"subvideo_data":[
{
"_id":"61b6f8a3ba3b7a3d10d0afe2",
"pageNo":1,
"subvideo_title":"hhghgghghgg",
"subdescription":"vfgv",
"booksVideo":"https://hashvideo.s3.ap-south-1.amazonaws.com/Screenshot%20%28166%29.png",
"booksImage":"https://bookstoreimage.s3.ap-south-1.amazonaws.com/Screenshot%20%28166%29.png",
"subreleaseDate":null
},
{
"_id":"61b6f8a3ba3b7a3d10d0afe3",
"subvideo_title":"hhghgghghgg",
"subdescription":"hgjhjh",
"pageNo":2,
"booksImage":"https://bookstoreimage.s3.ap-south-1.amazonaws.com/Screenshot%20%28166%29.png",
"booksVideo":"https://hashvideo.s3.ap-south-1.amazonaws.com/Screenshot%20%28166%29.png",
"subreleaseDate":"2021-12-13T07:39:15.412Z"
}
]
}
],
"book_created_date":"2021-12-13T07:39:15.414Z"
}
here is my mongoose schemawhich im using to save it.
const mongoose = require('mongoose')

const BooksStoreSchema = mongoose.Schema({

book_title : {
type: String,
required:[true,"enter your book name"] 
},
book_authore: { 
type: String,
required:[true,"enter your book author name"] 
},

book_overview: {
type: String,
required:[true,"enter your book description"] 
}, 
book_publication: {
type: String,
required:[true,"enter your book publication name"] 
},
book_category: {
type: String,
required:[true,"enter book category name"] 
}, 

book_genre: {
type: String,
enum: ["Feel Good Novels", "Trending Now", "Fiction", "Best sellers", "Originals","Internationals"]
}, 

book_tag: {
type: String,
required:true,
enum: ["comedy","thriller","horror"]
}, 
book_rating_count :{
type:Number,
default:0
},
book_languages :{
type:String,
required:true
},
book_duration :{
type:String,
required:true
},
book_rating :{
type:Number,
required:true
},
booksEpdf:{
type:String,
required:true
},
booksAudio:{
type:String,
required:true
},
video_data: [{

number_of_chapters:{
type:Number,
required:true,
},
video_title: {
type:String,
required:true
},
description:{
type:String,
required:true
},
booksVideo:{
type:String,
required:true
},
booksImage:{
type:String,
required:true
},
releaseDate:{
type: Date,
default: Date.now,
},
subvideo_data: [{
pageNo:{
type:Number,
required:true
},

subvideo_title:{
type:String,
required:true
},
subdescription:{
type:String,
required:true
},
booksVideo: {
type:String,
required:true
},
booksImage: {
type:String,
required:true
},
subreleaseDate:{
type: Date,
default: Date.now,
},
},
],
}],
//like view and created schema..... 
book_review: {
type: Number,
default: 0,
},
book_like: {
type:Number,
default:0
},
book_created_date: {
type: Date,
default: Date.now,
},
});
module.exports = mongoose.model('booksStore', BooksStoreSchema)
here is my controller....
router.post('/',    function(req, res,next) {
const booksStore = new BooksStore({
book_title : req.body.book_title,
book_authore : req.body.book_authore,
book_overview : req.body.book_overview,
book_category : req.body.book_category,
book_genre :req.body.book_genre,
book_tag : req.body.book_tag,
book_languages: req.body.book_languages,
book_duration : req.body.book_duration,
book_rating : req.body.book_rating,
book_publication : req.body.book_publication,
book_rating_count:req.body.book_rating_count,
booksEpdf:  req.body.booksEpdf,
booksAudio: req.body.booksAudio,
video_data:req.body.video_data,
book_review:req.body.book_review,
book_like:req.body.book_like,
book_created_date:req.body.book_created_date,

});
console.log(JSON.stringify(booksStore)+"datahhhhhhhhhhhhhhhhhhh")
booksStore.save()
.then(result => {
res.status(200).send({
_id: result._id,
message:"submit successfully"
})
})
.catch(err => {
res.send({ message: err })
})
})

actully i was used dynamic form in react, i want to save this data,please help me how can i solve this issue??

为了解决这种问题,您需要验证您的代码,是否有任何_id已经在您的react this中声明。状态如果您已经声明了任何与数据库响应匹配的id,比如这个id,那么转到您的代码,只需修改或删除它,然后重试。这将是工作

相关内容

最新更新