How to replace an element in an array field in mongodb
问题 Field tags is array in scenes document. I wanna replace element 'Bad' with 'Good' in the array as: db.scenes.update({ 'tags': 'Bad' }, { $set: { 'tags.$' : 'Good' } }, { 'multi':true}); I don't know how to do it in doctrine. I tried $dm->createQueryBuilder('SceneBundle:Scene') ->update() ->field('tags.$')->set($tag) ->field('tags')->equals($oldTag) ->multiple(true) ->getQuery() ->execute(); but not work. Thanks. 回答1: There isn't a single replace function for this, but you can do it in one