I have this mongoose schema :
var BookSchema = new mongoose.Schema({
title: {
type: String, required: true
},
description: {
type: String, required: true
},
questions:[{
_id : {type: mongoose.Schema.ObjectId, ref: 'Question'},
value: {type: Number, default: -1}
}]
});
And QuestionSchema :
var QuestionSchema = new mongoose.Schema({
title: {
type: String, required: true, unique: true
}
});
I'm trying to add "questions" in the array but I have a "CastError" when I do :
Book.update({'_id': req.params.id}, {$addToSet: {'questions._id': tabQuestions}}, function(err) {
if (err)
console.log(err);
});
Th array "tabQuestions" is an array with string which are the ObjectID of a Question. For exemple : ["551950a8a0927a741c6c1d46","551950c0a0927a741c6c1d47"]
I don't understand why I have this error :
Cast to ObjectId failed for value \"551950a8a0927a741c6c1d46,551950c0a0927a741c6c1d47\" at path \"_id\""
Aucun commentaire:
Enregistrer un commentaire