Google\Cloud\Datastore\DatastoreClient::upsertBatch PHP Method

upsertBatch() public method

Upsert will create a record if one does not already exist, or overwrite an existing record if one already exists. Please note that upserting a record in Cloud Datastore will replace the existing record, if one exists. Adding, editing or removing a single property is only possible by first retrieving the entire entity in its existing state. Upsert by this method is non-transactional. If you need transaction support, use {@see \Google\Cloud\Datastore\Transaction::upsertBatch()}. Example: $keys = [ $datastore->key('Person', 'Bob'), $datastore->key('Person', 'John') ]; $entities = [ $datastore->entity($keys[0], ['firstName' => 'Bob']), $datastore->entity($keys[1], ['firstName' => 'John']) ]; $datastore->upsertBatch($entities);
public upsertBatch ( array $entities, array $options = [] ) : array
$entities array The entities to be upserted.
$options array [optional] Configuration Options.
return array [Response Body](https://cloud.google.com/datastore/reference/rest/v1/projects/commit#response-body)
    public function upsertBatch(array $entities, array $options = [])
    {
        $mutations = [];
        foreach ($entities as $entity) {
            $mutations[] = $this->operation->mutation('upsert', $entity, Entity::class);
        }
        return $this->operation->commit($mutations, $options);
    }