Messages.update(
{_id: docId, "messages.senderId": friendId},
{
$set: {"messages.$[elem].read": true}
},
{
multi: true,
arrayFilters: [{"elem.senderId": friendId}]
},
(err, result) => {
if (err) {
return res.status(500).json({message: "Something error occured" + err})
} else {
return res.status(200).json({message: "Successfully", result})
}
}
)
when this command execute I get an error.
Could not find path "messages.0.senderId" in schema"
and my schema is
const Schema = new mongoose.Schema({
conversations: Array,
messages: Array
})
How can solve this problem?,
please, help me.
i follow this solution but not work.
2
Answers
This is a
moongoose
error as your schema does not specify the complete structure.You can see here that the Mongo update syntax is working as expected.
It seems this is a missing feature for now, As seen in the source code (
mongoose v6
)The comment acknowledges this bad behaviour, but this is still the logic used even for "mixed type" arrays.
You can either:
strict: false
option in the update, this will also disable other validations which means it’s the less preferable approach:This is a
moongoose
error as your schema does not specify the complete structure.You can see here that the Mongo update syntax is working as expected.
It seems this is a missing feature for now, As seen in the source code (
mongoose v6
)The comment acknowledges this bad behaviour, but this is still the logic used even for "mixed type" arrays.
You can either:
strict: false
option in the update, this will also disable other validations which means it’s the less preferable approach: