doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 504 forks source link

Why a document with array of embedded documents inside is sent 2x via updateOne instead of 1x? #2695

Closed pkowalski700lm closed 6 days ago

pkowalski700lm commented 1 week ago
Q A
Version x.y.z

Support Question

I want to understand why doctrine works that way, that when i persist and flush a document with collection of embedded documents inside, it is sent to Mongo with 2 seperate upserts instead of 1 atomic updateOne containing all of the data ( 2nd updateOne sends all the arrays of embedded documents, first updateOne sends all the rest, non array embedded documents).

malarzm commented 6 days ago

This is done because we have several strategies for updating array of objects. If you want everything in a single query, please use atomicSet (for associative arrays) or atomicSetArray (for lists).

Docs: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.7/reference/storage-strategies.html#atomicset