Reputation: 15137
I can't seem to get this to work. Is there a better possibility or option instead of a findandmodify in this case?
db.runCommand(
{
findAndModify: "articles",
query: {"comments._id": ObjectId("515221650be1684cb9000002")},
new: true,
update: {"$push":{"comments.votes.up":"511cff226d6e0d1f20000001"}, "$inc":{"comments.votes.count":1, "comments.votes.up_count":1, "comments.votes.point":1}}
}
)
Upvotes: 1
Views: 702
Reputation: 4560
Is comment is subdocument collection ? if yes then is it that you are missing $ sign. like comments.$.votes.up . Try out this one . It will work
db.runCommand(
{
findAndModify: "articles",
query: {"comments._id": ObjectId("515221650be1684cb9000002")},
new: true,
update: {"$push":{"comments.$.votes.up":"511cff226d6e0d1f20000001"}, "$inc":{"comments.$.votes.count":1, "comments.$.votes.up_count":1, "comments.$.votes.point":1}}
}
)
Upvotes: 2