Doctrine / MongoDB / Strategy - Update documents with save / reset

I run unit tests on mongo db docs ... and found that the only way I could update an existing object after searching for it was to set (strategy = "set") inside Annotations. Does anyone know why this needs to be installed? And even better, what exactly does this change when using this setting?

+4
source share
1 answer

The strategy="set" attribute refers to the @Collection annotation on the document property:

http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html#collection

eg:

 class User { /** @Collection(strategy="set") */ public $tags; } 

The default value for the strategy is pushAll , which will add new values ​​added to the $tags array.

With set $tags array will overwrite the value stored in db.

0
source

Source: https://habr.com/ru/post/1396526/


All Articles