I am trying to delete entire user records from firestore using cloud functions but encounters the next error
INVALID_ARGUMENT: maximum 500 writes allowed per request
How to workaround this?
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.deleteUserContacts = functions
    .runWith({
        timeoutSeconds: 540,
        memory: '2GB'
    })
    .https.onCall((data,context) => {
    // ...
    return admin.firestore().collection('contacts').where('uid','==',context.auth.uid).get()
        .then(snap => {
            if (snap.size === 0) {
                console.log(`User ${context.auth.uid} has no contacts to delete`);
                return 'user has no contacts to delete';
            }
            let batch = admin.firestore().batch();
            snap.forEach(doc => {
                batch.delete(doc.ref)
            });
            return batch.commit(); //INVALID_ARGUMENT: maximum 500 writes allowed per request
        })
        .then(() => {
            console.log(`Transaction success on user ${context.auth.uid}`);
            return 'Transaction success';
        })
        .catch(error => {
            console.log(`Transaction failure on user ${context.auth.uid}`,error);
            throw new functions.https.HttpsError(
                'unknown',
                'Transaction failure'
              );
        });
});
 
    