How to add timestamp to every collection insert,update in Cloud Functions for firestore database

后端 未结 6 525
心在旅途
心在旅途 2020-11-29 09:23

I have a firestore collection called Posts I make an insert on the client side and it works.

I want to add the createdAt and updatedAt fields to every insert in my p

6条回答
  •  旧时难觅i
    2020-11-29 10:21

    You do not need Cloud Functions to do that. It is much simpler (and cheaper) to set server timestamp in client code as follows:

    var timestamp = firebase.firestore.FieldValue.serverTimestamp()   
    post.createdAt = timestamp
    post.updatedAt = timestamp
    

提交回复
热议问题