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

前端 未结 2 899
离开以前
离开以前 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: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()
          }
        });
    });
    

提交回复
热议问题