Get Key for object created after Push (Angular and Firebase)

后端 未结 1 941
轻奢々
轻奢々 2021-01-24 12:30

I\'m having problems understanding how to use Firebase. I wrote a function to push some data in my firebase database. I need to get the Key generated after I push the data into

相关标签:
1条回答
  • 2021-01-24 13:17

    I would make a small change to the post line and add / to the transactions

    postData(order: orderInfo) {
        let uid = firebase.auth().currentUser.uid;
    
    // Change this next line to save the transaction
    
        var newRef = this.db.list('/transactions').push({
          currency: order.currency,
          total: order.total,
          rate: order.rate,
          uid: uid
        });
    
    // get just the key reference
    var newKey= newRef.key;
    
    //then change this refer
    
        console.log(newKey);
    
    //To update you would change the next line
    
        this.db.list('transactionsPerUser').update(newKey, order.newInfo);
    }
    
    0 讨论(0)
提交回复
热议问题