【问题标题】:FireStore : How to update Field in object data structure in firestore using cloud functionsFireStore:如何使用云功能更新 Firestore 中对象数据结构中的字段
【发布时间】:2018-04-05 04:04:20
【问题描述】:

我以对象形式存储数据,我想使用云功能向每个对象(如受邀者 1 和受邀者 2)添加或更新一个像“状态”这样的文件。我试过但它在所有对象的末尾更新。如何使用云函数或 Firestore 触发器在每个对象的末尾添加字段。当我使用更新语句时出现这种类型的错误

var dbref = db1.collection('deyaPayUsers').doc(sendauthid).collection('Split').doc(sendauthid).collection('SentInvitations').doc(senderautoid);
var msg1 = receiverph +"" + status +" to pay $"+document.Amount;
var fulldoc = dbref.get()
                   .then(doc => {
if(!doc.exists){
                   console.log('No such document');
                   }else{
                   console.log('Document data :',doc.data());
                       d1 = doc.data();
                       console.log("d1 is"+d1);
for(var k in d1){
var p = d1[k].PhoneNumber;
                                      console.log("ivitees phone"+p);
if(receiverph == p)
                                      {
                                           console.log("p"+PhoneNumber);


                                           console.log("the phonenumber matches");
var updated =  dbref.p.update({"Status":status});// **i got error here like "update is not define"**

我尝试了另一种更新方式

var updated = dbref.d1[k].PhoneNumber.update({"Status":status});// 出现“无法读取未定义的受邀者 1 的属性”之类的错误

如何解决该错误。

【问题讨论】:

  • dbref.p 是什么?
  • p 变量将电话号码存储在特定对象中

标签: javascript firebase google-cloud-firestore


【解决方案1】:

您不能直接更新该字段。这样做:

有文档参考,

for(var k in d1) {
  if (receiverph  === d1[k].PhoneNumber) {
    doc.ref.update({
      [`${k}.Status`]: status
    })
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-02
    • 1970-01-01
    • 2019-12-13
    • 2020-02-19
    • 2020-01-09
    • 2020-02-08
    • 2019-08-07
    • 2018-06-11
    相关资源
    最近更新 更多