angular/fire 使用 startAfter 获取集合中的下一项
angular/fire get next item in collection using startAfter
我在使用 angular/fire
获取集合中的下一项时遇到了真正的问题
我得到的错误是:
Error: Function startAfter() called with invalid data. Unsupported field value: a custom AngularFirestoreDocument object
基于这些 Firebase docs I think startAfter() wants a DocumentSnapshot but I don't know how to convert AngularFirestoreDocument
to DocumentSnapshot
and whilst the angular/fire docs 提及 startAfter
他们没有给出任何代码示例。
这是我的问题代码。我想要集合中 video
文档之后的第一个文档。
getNextVideo$(id: string, group: string): Observable<IVideo> {
const video: AngularFirestoreDocument<IVideo> = this.afs.doc<IVideo>(`videos/${id}`)
const collection: AngularFirestoreCollection<IVideo> = this.afs.collection<IVideo>('videos', ref => {
return ref
.where('group', '==', group)
.where('flowPlayerProcessed', '==', true)
.orderBy('timeCreated')
.startAfter(video) // <<<<< ERROR IS HERE
.limit(1)
})
return collection.valueChanges().pipe(
map((videos: IVideo[]) => videos.length ? videos[0] : null)
)
}
提前致谢
好的,这个相当冗长的怪物有效
getNextVideo$(id: string, group: string): Observable<IVideo> {
const video: AngularFirestoreDocument<IVideo> = this.afs.doc<IVideo>(`videos/${id}`)
return video.snapshotChanges().pipe(
switchMap((videoSnapshotAction: Action<DocumentSnapshot<IVideo>>) => {
const videoSnapshot: DocumentSnapshot<IVideo> = videoSnapshotAction.payload
const collection: AngularFirestoreCollection<IVideo> = this.afs.collection<IVideo>('videos', ref => {
return ref
.where('group', '==', group)
.where('flowPlayerProcessed', '==', true)
.orderBy('timeCreated')
.startAfter(videoSnapshot)
.limit(1)
})
return collection.valueChanges().pipe(
map((videos: IVideo[]) => videos.length ? videos[0] : null)
)
})
)
}
我在使用 angular/fire
获取集合中的下一项时遇到了真正的问题我得到的错误是:
Error: Function startAfter() called with invalid data. Unsupported field value: a custom AngularFirestoreDocument object
基于这些 Firebase docs I think startAfter() wants a DocumentSnapshot but I don't know how to convert AngularFirestoreDocument
to DocumentSnapshot
and whilst the angular/fire docs 提及 startAfter
他们没有给出任何代码示例。
这是我的问题代码。我想要集合中 video
文档之后的第一个文档。
getNextVideo$(id: string, group: string): Observable<IVideo> {
const video: AngularFirestoreDocument<IVideo> = this.afs.doc<IVideo>(`videos/${id}`)
const collection: AngularFirestoreCollection<IVideo> = this.afs.collection<IVideo>('videos', ref => {
return ref
.where('group', '==', group)
.where('flowPlayerProcessed', '==', true)
.orderBy('timeCreated')
.startAfter(video) // <<<<< ERROR IS HERE
.limit(1)
})
return collection.valueChanges().pipe(
map((videos: IVideo[]) => videos.length ? videos[0] : null)
)
}
提前致谢
好的,这个相当冗长的怪物有效
getNextVideo$(id: string, group: string): Observable<IVideo> {
const video: AngularFirestoreDocument<IVideo> = this.afs.doc<IVideo>(`videos/${id}`)
return video.snapshotChanges().pipe(
switchMap((videoSnapshotAction: Action<DocumentSnapshot<IVideo>>) => {
const videoSnapshot: DocumentSnapshot<IVideo> = videoSnapshotAction.payload
const collection: AngularFirestoreCollection<IVideo> = this.afs.collection<IVideo>('videos', ref => {
return ref
.where('group', '==', group)
.where('flowPlayerProcessed', '==', true)
.orderBy('timeCreated')
.startAfter(videoSnapshot)
.limit(1)
})
return collection.valueChanges().pipe(
map((videos: IVideo[]) => videos.length ? videos[0] : null)
)
})
)
}