Reputation: 1101
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?
Upvotes: 5
Views: 2263
Reputation: 311865
Use the positional operator $
to identify the matched array element to update:
User.update( {'myplaylists._id': 2}, {$inc: { 'myplaylists.$.likes': 1 }}
Upvotes: 5