This pull request adds a merge() method to the Document class. It modifies list and map properties like PHP's array_merge() function.
use com\mongodb\{Document, ObjectId};
$doc= new Document(['_id' => ObjectId::create(), 'list' => [1, 2, 3]]);
// This does not work - offsetGet() creates a copy of the array!
$doc['list'][]= 4;
// What we need to do
$doc['list']= array_merge($doc['list'] ?? [], [4]);
// New functionality:
$doc->merge('list', [4]);
This pull request adds a
merge()
method to the Document class. It modifies list and map properties like PHP's array_merge() function.