I have a document as follows:
{
"_id" : "1",
"myplaylists" : [{
"_id" : "2",
"name" : "Playlist_0",
"likes" : 712,
"views" : 7110
}],
"name" : "First name, Last name"
}
and I want to do an update and increment "myplaylists.likes"
what I did is:
User.update( {'myplaylists._id': 2}, {$inc: { 'myplaylists.likes': 1 }}
but it doesn't seem to work because of the dot notation in the $inc
Any ideas how to do it?
Use the positional operator $
to identify the matched array element to update:
User.update( {'myplaylists._id': 2}, {$inc: { 'myplaylists.$.likes': 1 }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With