im very new with nodejs. Currently, im doing a increment a value into an array object. I have an error after write this code. I want to increment the value of linkview
. i found something similar with my problem Mongoose - Increment a value inside an array of objects but i still cannot solve it. Please help
So this is User
schema
{
"_id": "67324b2cc6817758118e9557d8",
"name": "James",
"__v": 0,
"affiliatelink": [
{
"storeId": 60014d6e7286763490c3543,
"storeName": white choc,
"linkview": 1
}
]
}`
and this is my code and the error is MongoError: The positional operator did not find the match needed from the query
Admin.findByIdAndUpdate({ _id: adminId }, {$inc: {"affiliatelink.$.linkview": 1}}, function(err, result) {
console.log("ni error "+err)
//if (err) return next(err)
});