[英]Firebase document deletion odd number of segments
I'm trying to delete an entry from firebase upon clicking a button in my table, but i get this error:我试图通过单击表中的按钮从 firebase 中删除一个条目,但出现此错误:
FirebaseError: Invalid document reference.
FirebaseError:无效的文档引用。 Document references must > have an even number of segments, but iEwblJo832nnC6TkFDEy has 1.
文档引用必须 > 有偶数个段,但 iEwblJo832nnC6TkFDEy 有 1 个。
I don't understand why the document has an odd number of segments since I just queried it.我不明白为什么文档的段数是奇数,因为我只是查询它。 How can i fix this?
我怎样才能解决这个问题?
The function which does the query select and attempts deletion查询 select 并尝试删除的 function
async deleteMovie(movieToDelete : Movie) {
await this.moviesRef.ref.where('includedBy', '==', movieToDelete.includedBy).where('title', '==', movieToDelete.title).get().then((querySnapshot) => {
querySnapshot.forEach((doc) => this.database.doc(doc.id).delete());
});
return true;
}
The click function of the delete button删除按钮的点击 function
async deleteEntry (item : Movie) {
let idx = this.movieData.data.indexOf(item);
if(await this.movieService.deleteMovie(this.movieData.data[idx]) === true) {
this.movieData.data.splice(idx,1);
this.movieData._updateChangeSubscription();
}
else {
window.location.reload();
}
}
The html page where the button is created创建按钮的html页面
<div class="container-page">
<p id="toolbar-top">
<mat-toolbar color="primary">
Welcome (de pus numele userului aici)
<button mat-icon-button id="logout-icon">
<mat-icon>logout</mat-icon> Logout
</button>
</mat-toolbar>
</p>
<table class="mat-elevation-z8 table-main" mat-table [dataSource]="movieData" matSort>
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Title </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<ng-container matColumnDef="genre">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Genre </th>
<td mat-cell *matCellDef="let element"> {{element.genre}} </td>
</ng-container>
<ng-container matColumnDef="watchStatus">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let element"> {{element.watchStatus}} </td>
</ng-container>
<ng-container matColumnDef="rating">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Rating </th>
<td mat-cell *matCellDef="let element"> {{element.rating}} </td>
</ng-container>
<ng-container matColumnDef="wouldRecommend">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Recommended ? </th>
<td mat-cell *matCellDef="let element"> {{element.wouldRecommend}} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef ></th>
<td mat-cell *matCellDef="let row" >
<button mat-raised-button color="warn" (click)="deleteEntry(row)">Delete</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator class="paginator-main" [pageSizeOptions]="[5, 10, 15]"
showFirstLastButtons
aria-label="Select page of movies list">
</mat-paginator>
<button id="new-entry-button" mat-raised-button color="primary" (click)="addNewEntry()">Add new movie</button>
</div>
The movie interface电影界面
export interface Movie {
includedBy : string;
title : string;
genre : string;
watchStatus : string;
rating : string;
wouldRecommend : string;
}
This is how my firebase collection looks like这就是我的 firebase 系列的样子
You're querying this.moviesRef
, but then are deleting from this.database
, so it seems those two references are different.您正在查询
this.moviesRef
,但随后正在从this.database
中删除,因此这两个引用似乎不同。
To delete from a query, you can just get the reference of the document snapshot in the result itself:要从查询中删除,您只需在结果本身中获取文档快照的引用:
this.moviesRef.ref
.where('includedBy', '==', movieToDelete.includedBy)
.where('title', '==', movieToDelete.title)
.get().then((querySnapshot) => {
querySnapshot.forEach((doc) => doc.ref.delete());
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.