I may have discovered an obscure issue with Doctrine Mongo ODM, or this may just be me using the document manager incorrectly, but either way thought I'd post the issue here and my workaround for the benefit of the community.
Imagine you have three classes, A, B and X. Class X can be embedded into either A or B (note embedded, not referenced). If you follow this sequence of steps, you'll get an exception:
$a = $dm->getRepository('A')->find($id_a);
$b = $dm->getRepository('B')->find($id_b);
$dm->persist($b); // May not be necessary but doesn't seem to hurt
This arises because, at the point Doctrine tries to update $b in the database, there is still an instance of class X inside $a. I wouldn't expect this to prevent me from committing the change to $b to the database, but for some reason it does.
In my case, the workaround was simple: because I only needed to modify one object, I could detach the other from the document manager from attempting the flush.
However, it would be more convenient to be able to fetch both, modify either or both, then flush the change and let the document manager sort it out, without having to worry about detaching the unmodified object.