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);