gpt4 book ai didi

javascript - Firestore where 语句与 array-contains 不起作用

转载 作者:行者123 更新时间:2023-12-03 00:47:24 25 4
gpt4 key购买 nike

我检查我的数据库以获取引用(存在),但没有收到任何聊天记录,但我不知道在哪里。

chat.service.ts:

  getUserChats(): Observable<Chat[]> {
let uid = '-1';
this.auth.currUser.subscribe(user => (uid = user.uid));
this.chats = this.afs
.collection('chats', ref => ref.where('members', 'array-contains', `users/${uid}`))
.snapshotChanges()
.pipe(
map(actions => {
return actions.map(action => {
const data = action.payload.doc.data() as Chat;
const id = action.payload.doc.id;
return {id, ...data};
});
})
) as Observable<Chat[]>;
return this.chats;
}

该代码的目的是获取登录用户所属的所有聊天。我通过检查成员数组(如果有任何对他的引用)来做到这一点。

chat.component.ts:

chats: Observable<Chat[]>;
constructor(private router: Router, public chatService: ChatService, public dialog: MatDialog, public auth: AuthService) { }

ngOnInit() {
this.chats = this.chatService.getUserChats();
}

chat.component.html:

<mat-list-option *ngFor="let chat of chats | async" (click)="handleClick(chatList)" [value]="chat.id">
<img matListAvatar src="./assets/avatar.svg" alt="Avatar Icon">
<h3 mat-line>{{chat.name}}</h3>
<p mat-line>test</p>
</mat-list-option>

聊天结构:

model

最佳答案

显然,您正在查询users/uid,而数据库中存储的是/users/uid,请参阅第一个/

关于javascript - Firestore where 语句与 array-contains 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53187513/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com