I am trying to push a new element into an array, I use mongoose on my express/nodejs based api. Here is the code for mongoose:
Serie.updateOne({'seasons.episodes.videos._id': data._id}, {$push: {'seasons.episodes.videos.$.reports': data.details}},
function(err) {
if (err) {
res.status(500).send()
console.log(err)
}
else res.status(200).send()
})
as for my series models, it looks like this:
const serieSchema = new mongoose.Schema({
name: {type: String, unique:true, index: true, text: true},
customID: {type: Number, required: true, unique: true, index: true},
featured: {type: Boolean, default: false, index: true},
seasons: [{
number: Number,
episodes: [{number: Number, videos: [
{
_id: ObjectId,
provider: String,
reports: [{
title: {type: String, required: true},
description: String
}],
quality: {type: String, index: true, lowercase: true},
language: {type: String, index: true, lowercase: true},
}
]}]
}],
});
When I execute my code, I get MongoDB error code 16837, which says "cannot use the part (seasons of seasons.episodes.videos.0.reports) to traverse the element (my element here on json)"
I've tried many other queries to solve this problem but none worked, I hope someone could figure this out.