Doctrine ODM - 如何通过传递字段名称来设置文档中的值

I have a MongoDB Document called User. I also have the array containing all possible "updatable" fields (this is for an API where a third party can update fields in my DB by sending a request). I want to do something like:

$user_document->set(array($field => $value));
$document_manager->flush();

Where $user_document is the document got by FindOneBy, and $field and $value are the values from the API request. This does not work. How to manually insert value to a given field? I dont want to use setFieldName method, because there are a lot of fields and I want to keep them in an array.

I've solved the problem, here's the correct approach:

$result = $document_manager
    ->createQueryBuilder('AppBundle:User')
    ->findAndUpdate()
    ->returnNew()
    ->field($field)->set($value)
    ->field('id')->equals($given_id)
    ->getQuery()
    ->execute();