How to pass admin.firestore.FieldValue.serverTimestamp() to the update() method, using CloudFunction coded in TypeScript

前端 未结 2 900
离开以前
离开以前 2020-12-21 15:45

How to pass admin.firestore.FieldValue.serverTimestamp() to the update() method? I want to insert this in an array, like this:

import * as functions from \'         


        
相关标签:
2条回答
  • 2020-12-21 16:03

    Instead of admin.firestore.FieldValue.serverTimestamp(), you can use admin.firestore.Timestamp.now()

    const time = admin.firestore.Timestamp.now();
    await amisA.update({
            [`amis.${numeroSender}`] : 
               {
        connaissanceABBA: connaissanceABBA,
        version: version,
        ts: firebase.firestore.FieldValue.serverTimestamp()
      }
    });
    });
    
    0 讨论(0)
  • 2020-12-21 16:04

    As detailed in the error message you receive, "FieldValue.serverTimestamp() cannot be used inside of an array".

    Which is what you do with:

    const time = admin.firestore.FieldValue.serverTimestamp();
    await amisA.update({
                [`amis.${numeroSender}`] : [time,connaissanceABBA,version]
            });
    });
    

    You might have to change your data model and, for example, replace your array by a map, as follows:

    const time = admin.firestore.FieldValue.serverTimestamp();
    await amisA.update({
                [`amis.${numeroSender}`] : 
                   {
            connaissanceABBA: connaissanceABBA,
            version: version,
            ts: firebase.firestore.FieldValue.serverTimestamp()
          }
        });
    });
    
    0 讨论(0)
提交回复
热议问题