Firestore: Key writes does not exist in the provided array

Answer from Alexander is correct for specific situation.

More generic solution is to use function provided directly within Firestore, that checks if anything was enqueued to batch.

if (!$batch->isEmpty()) {
    $batch->commit();
}

Source: https://github.com/googleapis/google-cloud-php-firestore/blob/master/src/WriteBatch.php#L483


It tells you that you are running a commit, but batch contains no operations. Probably when your $memberList is empty this error shows up. An easy way to prevent the error is:

if (! empty($memberList)) {
    $batch->commit();
}

Also, are you sure that $batch->create() exists? You should use set() method. Here is latest firestore doc:

$batch = $db->batch();

# Set the data for NYC
$nycRef = $db->collection('cities')->document('NYC');
$batch->set($nycRef, [
    'name' => 'New York City'
]);

# Update the population for SF
$sfRef = $db->collection('cities')->document('SF');
$batch->update($sfRef, [
    ['path' => 'population', 'value' => 1000000]
]);

# Delete LA
$laRef = $db->collection('cities')->document('LA');
$batch->delete($laRef);

# Commit the batch
$batch->commit();