Add timestamp in Firestore documents

前端 未结 10 1040
旧巷少年郎
旧巷少年郎 2020-12-29 03:29

I\'m newbie to Firestore. Firestore docs says...

Important: Unlike \"push IDs\" in the Firebase Realtime Database, Cloud Firestore au

10条回答
  •  醉酒成梦
    2020-12-29 04:04

    The way it worked with me, is just taking the timestamp from the snapshot parameter snapshot.updateTime

    exports.newUserCreated = functions.firestore.document('users/{userId}').onCreate(async (snapshot, context) => {
    console.log('started!     v1.7');
    const userID = context.params['userId'];
    
    firestore.collection(`users/${userID}/lists`).add({
        'created_time': snapshot.updateTime,
        'name':'Products I ♥',
    }).then(documentReference => {
        console.log("initial public list created");
        return null;
      }).catch(error => {
        console.error('Error creating initial list', error);
        process.exit(1);
    });
    

    });

提交回复
热议问题