In my possession is a document structured as follows:
{
"id": "12345",
"channels": [
{
"id": "67890",
"count": 1
}
]
}
My objective is to increase the count of a specific channel by one. When a user sends a message, I must locate the user, identify the correct channel by its "id" within the "channels" array, and raise the "count" by one.
I experimented with the subsequent query:
UserModel.findOneAndUpdate({id: this.id},
{'channels.id': channel.id},
{$set: {$inc: {'channels.$.count': 1}}}
To my surprise, the execution did not result in an error. However, the count was also left unaffected.