Mongo+;PHP:使用新数组更新集合中的文档

Mongo+;PHP:使用新数组更新集合中的文档,php,mongodb,nosql,Php,Mongodb,Nosql,我正在尝试向集合中的现有文档添加新数组: $lat = '38.9586307'; $lon = '-77.3570028'; $location = 'office'; $latLong = array($lat,$lon); $newdata = array('$set' => array('latLong' => $latLong)); $collection->update(array('location' =>

我正在尝试向集合中的现有文档添加新数组:

    $lat = '38.9586307';
    $lon = '-77.3570028';
    $location = 'office';

    $latLong = array($lat,$lon);

    $newdata = array('$set' => array('latLong' => $latLong));

    $collection->update(array('location' => $location), $newdata);

但它不起作用……我是不是遗漏了什么?

我发现了,我需要在更新命令的末尾添加一个“多”文档更新条件:

$collection->update(array('location' => $location), $newdata, array("multiple" => true));

您能否在执行此代码之前和之后将该文档添加到您的问题转储中?您没有提到您有多个文档:)很高兴您找到了解决方案。