angular - 如何使用 Angular/Ionic 和 Stripe 扩展查询 firebase firestore 子集合以获取其他属性
问题描述
我正在将 Angular/Ionic 与 Firestore 和 Stripe 的 Firebase Extension for Subscriptions 一起使用。我已将产品添加到 Stripe 的后端,然后使用产品集合和定价子集合填充 Firestore。每种产品都有多种价格可供选择。我正在尝试查询产品和定价,以便在结帐页面上显示可供购买的产品。我可以获得产品,但我无法获得每种产品的价格。每种产品的定价差异是基于时间的(单个、每月、每年)。以下是 Stripe 如何在https://github.com/stripe/stripe-firebase-extensions/blob/master/firestore-stripe-subscriptions/POSTINSTALL.md的 github 页面上描述条带扩展的过程 列出可用的产品和价格产品和定价信息是 Cloud Firestore 中的正常集合和文档,可以这样查询:
db.collection('${param:PRODUCTS_COLLECTION}')
.where('active', '==', true)
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(async function (doc) {
console.log(doc.id, ' => ', doc.data());
const priceSnap = await doc.ref.collection('prices').get();
priceSnap.docs.forEach((doc) => {
console.log(doc.id, ' => ', doc.data());
});
});
});
这是我尝试过的:
const prodRef = this.afs
.collection<Product>('products', (ref) => ref.where('active', '==', true));
this.products = prodRef.valueChanges();
this.prices = await prodRef.snapshotChanges().pipe(
map((actions) => {
actions.map((a) => {
const data = a.payload.doc.data() as Product;
data.id = a.payload.doc.id;
return data;
});
})
);
// this.pricing = await prodRef.valueChanges().toPromise().then((querySnapshot) => {
// querySnapshot.forEach((doc) => {
// console.log(doc.id, ' => ', doc.data());
// const priceSnap = snapshotChanges collection('prices').get();
// priceSnap.docs.forEach((doc) => doc.data())
// })
// })
// snapshotChanges().pipe(map(actions => {
// actions.map(a => {
// const data = a.payload.doc.data();
// const id = a.payload.doc.id;
// return { id, ...data };
// });
// }));
解决方案
推荐阅读
- java - OOM 用 320 x 16MB Netty DirectByteBuffer 对象杀死了 JVM
- asp.net - 只有 POST 请求会抛出“502 - Web 服务器在充当网关或代理服务器时收到无效响应”。在 web api 调用中
- c# - 如何优化对字符串中所有给定关键字的搜索
- ios - 在 xcode 中找不到 URL 方案(用于颤振)
- django - 弹出页面说我们已经发送了一封电子邮件,但没有任何内容发送到我的电子邮件重置电子邮件Django
- vue.js - Vuetify 突然显示不同的边距?
- postgresql - postgresql如何返回一定长度的数字
- python - 如何将日期时间向量转换为 UTC?
- android - NestedRecyclerView 问题 - 键盘出现后第二个 RecyclerView 的最后一项复制到第一个
- html - jinja2 不能切片元素