Я хочу установить связь между моей таблицей, но когда я вставляю новый Personnage, у меня появляется ошибка. Я не понимаю, почему у меня эта ошибка только с "ethn ie".
Спасибо за вашу помощь
Это мои таблицы,
const royaume = new mongoose.Schema({
_id : String,
nom_royaume: String,
image_royaume: String,
description_royaume: String
})
const Royaume = mongoose.model('Royaume', royaume)
const jeu = new mongoose.Schema({
_id : String,
nom_jeu: String,
image_jeu: String
})
const Jeu = mongoose.model('Jeu', jeu)
const ethnie = new mongoose.Schema({
_id : String,
nom_ethnie: String,
image_ethnie: String,
description_ethnie: String
})
const Ethnie = mongoose.model('Ethnie', ethnie)
const personnage = new mongoose.Schema({
_id : String,
nom_personnage: String,
image_personnage: String,
description_personnage: String,
Jeux: [{type: mongoose.Schema.Types.ObjectId,ref:'Jeu'}],
Ethnie: {type: mongoose.Schema.Types.ObjectId,ref:'Ethnie'},
Royaume: {type: mongoose.Schema.Types.ObjectId,ref:'Royaume', required : true}
})
const Personnage = mongoose.model('Personnage', personnage)
и это мой новый Персонал
new Personnage({
_id : "personnage_" + (Math.floor(Math.random() * Math.floor(10000))).toString(),
nom_personnage : req.body.inputNom,
image_personnage : req.body.inputImage,
description_personnage : req.body.inputDesc,
Jeux : [],
Royaume : req.body.id_royaume,
Ethnie : req.body.id_ethnie
})
Ошибка:
{ _id: 'royaume_1453',
nom_royaume: 'Sarasaland',
image_royaume: 'https://66.media.tumblr.com/0697b65d318912d7ef010c1d396e7d69/tumblr_pomnpy6Tqf1w3693do2_500.png',
description_royaume: 'Le royaume de Sarasaland',
__v: 0 }
{ _id: 'ethnie_861',
nom_ethnie: 'Koopa',
image_ethnie:
'https://vignette.wikia.nocookie.net/mario/images/f/f0/Koopa-0.png/revision/latest?cb=20181117162734&path-prefix=fr',
description_ethnie: 'L\'ethnie des koopas',
__v: 0 }
{ ValidationError: Personnage validation failed: Ethnie: Cast to ObjectID failed for value "ethnie_861" at path "Ethnie"
at ValidationError.inspect (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\error\validation.js:59:24)
at formatValue (internal/util/inspect.js:493:31)
at inspect (internal/util/inspect.js:191:10)
at Object.formatWithOptions (util.js:84:12)
at Console.(anonymous function) (console.js:196:15)
at Console.warn (console.js:213:31)
at Personnage.save.then.catch.err (C:\Users\jerom\Desktop\Projet\projet_nodejs\server.js:413:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
errors:
{ Ethnie:
{ CastError: Cast to ObjectID failed for value "ethnie_861" at path "Ethnie"
at new CastError (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\error\cast.js:29:11)
at model.$set (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\document.js:1022:7)
at model._handleIndex (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\document.js:797:14)
at model.$set (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\document.js:743:22)
at model.Document (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\document.js:119:12)
at model.Model (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\model.js:93:12)
at new model (C:\Users\jerom\Desktop\Projet\projet_nodejs\node_modules\mongoose\lib\model.js:4502:13)
at router.route.get.post (C:\Users\jerom\Desktop\Projet\projet_nodejs\server.js:401:5)
at process._tickCallback (internal/process/next_tick.js:68:7)
message:
'Cast to ObjectID failed for value "ethnie_861" at path "Ethnie"',
name: 'CastError',
stringValue: '"ethnie_861"',
kind: 'ObjectID',
value: 'ethnie_861',
path: 'Ethnie',
reason: [MongooseError] } },
_message: 'Personnage validation failed',
name: 'ValidationError' }
ошибка изображения