Deleting Data
Unless being run in a transaction, all delete operations return a Promise which resolves once the mutation is applied on the server.
Delete
To delete a document, call the delete method on a DocumentReference:
Client code
const userRef = squid.collection<User>('users').doc('existing_user_id');
try {
await userRef.delete();
console.log('User deleted successfully');
} catch (error) {
console.error(`Failed to delete user ${error}`);
}
Delete many
To delete multiple documents in a batch, use the deleteMany method. deleteMany takes an array of documents or document IDs as a parameter.
Client code
const staleDocs = await squid.collection<User>('users').query().eq('pending-delete', true);
try {
await squid.collection<User>('users').deleteMany(staleDocs);
console.log('users successfully deleted');
} catch (error) {
console.error(`Failed to delete users ${error}`);
}
Delete In Path
To delete a specific property of a document, call the deleteInPath method on a DocumentReference and pass in
the path to the property you want to delete. Use dot notation to specify nested properties in the path:
Client code
const userRef = squid.collection<User>('users').doc('existing_user_id');
try {
await userRef.deleteInPath('contact.email');
console.log('User email deleted successfully');
} catch (error) {
console.error(`Failed to delete user email ${error}`);
}