1

これを機能させることができないようです。この場合、findandmodifyの代わりに、より良い可能性またはオプションがありますか?

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}}
                }
             )
4

1 に答える 1

2

コメントはサブドキュメントコレクションですか?はいの場合、$記号が欠落しているということです。コメントのように。$。votes.up。これを試してみてください。それが動作します

       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}}
            }
         )
于 2013-03-27T16:52:00.177 に答える