Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase Firestore中条带支付的数据模型_Firebase_Stripe Payments_Google Cloud Functions_Google Cloud Firestore - Fatal编程技术网

Firebase Firestore中条带支付的数据模型

Firebase Firestore中条带支付的数据模型,firebase,stripe-payments,google-cloud-functions,google-cloud-firestore,Firebase,Stripe Payments,Google Cloud Functions,Google Cloud Firestore,我遵循Google提供的教程()将Stipe与RTDB结合使用,并尝试将示例改编为与Firestore结合使用 本教程进行以下调用以向RTDB添加数据: const payment = { token, amount } return this.db.list(`/payments/${this.userId}`).push(payment) 我对在Firestore如何做到这一点的最佳猜测是: const payment = {token, 'price':this.props.price}

我遵循Google提供的教程()将Stipe与RTDB结合使用,并尝试将示例改编为与Firestore结合使用

本教程进行以下调用以向RTDB添加数据:

const payment = { token, amount }
return this.db.list(`/payments/${this.userId}`).push(payment)
我对在Firestore如何做到这一点的最佳猜测是:

const payment = {token, 'price':this.props.price}
var db = firebase.firestore()
db.collection('payments').doc(this.props.uid).collection('test').add(payment)

请注意,我有“test”集合,因为Firestore要求您在文档和集合之间切换。我认为这是在Firestore中构造数据的正确方法?

我认为您可以使用示例中显示的相同结构:

payments<collection>
    userId<doc>
        paymentId<field> : [
                            amount: number
                            token: object
                            charge: object 
                           ]
付款
用户ID
paymentId:[
金额:数字
令牌:对象
指控:反对
]

请注意,此处的令牌被视为地图。此解决方案是否适合您的需要?

当我将条带支付数据从Realtime移动到Firestore时,我遇到了类似的情况

我绕过它的方法是让我的顶级集合成为用户,每个文档都是一个用户uid,每个用户文档都有一个付款集合,我将新的付款添加到此集合中

我更喜欢这种方法,而不是将字段作为数组,因为它更容易查询

例如:

db.collection('users').doc(this.props.uid).collection('payments').add(payment);

我试图实现这个想法,但遇到了一个问题。下面是我尝试运行的:
db.collection('payments').doc(this.props.uid).update({paymentId:payment})
有什么问题吗?这是一个设计问题(你想要实现其他目标)还是你得到了一个错误?我能够看到数据,但现在我遇到了一个新问题:当我用新字段更新文档时,我不清楚如何使paymentId动态。目前,我的firestore数据库有字段“{paymentId}”
const payment={token,“price”:this.props.price}const paymentId=token.id var db=firebase.firestore()db.collection('paymentId').doc(this.props.uid)。set({{paymentId}):payment},{merge:true})