首页 > 解决方案 > How to add timestamp to my document in cloud Firestore using Firebase Python Admin SDK?

问题描述

I'm trying to add a timestamp value, along with other details to a comment document in Cloud Firestore. I would like to know how can I do it using Firebase Admin Python SDK. As far as I know to get server time stamp, in JS SDK you use

admin.firestore().Field value.serverTimestamp()

Is there any Python SDK equivalent of this?

标签: pythonfirebasegoogle-cloud-firestorefirebase-admin

解决方案


From the documentation:

To set a field to the current time on the server when the update is received, use the SERVER_TIMESTAMP sentinel.

>>> field_updates = {
...     'foo.now': firestore.SERVER_TIMESTAMP,
... }
>>> document.update(field_updates)

推荐阅读