【发布时间】:2021-01-26 03:12:36
【问题描述】:
我想使用 geofirex 根据用户的位置获取并加入多个集合:
这是我根据位置获取用户文档时的代码: PS(此代码仅根据位置返回用户的文档)
getAround() {
const center = geo.point(this.lat, this.lng);
const field = 'location';
this.points = this.radius.pipe(
switchMap(r => {
return this.geo.query(locations).within(center, r, field, { log: true });
})
);
}
我如何使用 Rxjs 内部加入集合:
getAll() {
const allPosts = this.afStore.collection<Service>('services')
.valueChanges()
.pipe(
switchMap(services => {
const res = services.map((service: Service) => {
return this.afStore.doc<UserModel>(`users/${service.userId}`)
.valueChanges()
.pipe(
map(user => Object.assign(service, { user }))
);
});
return combineLatest([...res]); })
)
.pipe(
switchMap(servuser => {
const ress = servuser.map((service: Service) => {
return this.afStore.doc<Category>(`categorys/${service.iconId}`)
.valueChanges()
.pipe(
map(category => Object.assign(service, { category }))
);
});
return combineLatest([... ress]);
})
);
return allPosts;
}
问题是我无法将这些代码混合在一起,因此我可以根据用户的位置加入我的数据,
我知道了error:
(alias) interface Service
import Service
Argument of type '(service: Service) => Observable<Service & { user: UserModel; }>' is not assignable to parameter of type '(value: GeoQueryDocument, index: number, array: GeoQueryOocument[]) => Observable<Service & { user: UserModel; }>'. Types of parameters 'service' and 'value' are incompatible.
Type 'GeoQuerpocument' is missing the following properties from type 'Service': id, cost, dateCreated, discount, and 6 more.
【问题讨论】:
标签: angular firebase google-cloud-firestore rxjs geofire