I am trying to delete parent and child objects where the child 'order' with field orderShared shares 'orders' unique id.
This is my order list
order: [
orderid: 'id1',
orderShared: 'idx1;
name: 'smth']
orders: [
ordersid: 'idx1',
name: 'smthelse']
this is how I am calling function in my pinia store and it throws me an error: Invalid document reference. Document references must have an even number of segments, but users/SXhPv4hvRUVPVN3mbBdjxSEffwB2/clients/lJpA7a33yBUZ3vQBsa9T/orders/sMuSSuTq1vJDlYLqKNfe/order has 7
ordersId in my method is unique ID of 'orders'
It seems that I am doing something wrong when I use where() and get() but I can't figure out what exactly is wrong.
deleteBatchOrders(ordersId) {
const storeAuth = useStoreAuth();
const batch = writeBatch(db)
const ordersDelete = this.getOrdersName(ordersId)
// const orderDelete = this.getOrderName(ordersId)
let orderRef = doc(db, 'users', storeAuth.user.id, 'clients', ordersDelete.clientShared, 'orders', ordersId, 'order')
let thisRef = orderRef.where('orderShared', '==', ordersId).get()
thisRef.forEach(doc => {
batch.delete(doc.ref)})
const ordersRef = doc(db, 'users', storeAuth.user.id, 'clients', ordersDelete.clientShared, 'orders', ordersId)
batch.delete(ordersRef)
batch.commit()
return alert('Orders deleted')
},