Firebase Firestore Server Timestamp with firebase-admin python sdk

 ̄綄美尐妖づ 提交于 2020-05-16 03:13:08

问题


There is a way to add server timestamps in firebase-admin python sdk? I try:

firestore.SERVER_TIMESTAMP
firestore.constants.SERVER_TIMESTAMP

but, i get this exception:

TypeError: ('Cannot convert to a Firestore Value', <object object at 0x10380fc20>, 'Invalid type', <class 'object'>)

回答1:


firestore.SERVER_TIMESTAMP worked for me. Here's the full example:

import firebase_admin
from firebase_admin import firestore

# I have GOOGLE_APPLICATION_CREDENTIALS configured.
firebase_admin.initialize_app()
client = firestore.client()
result = client.collection('test').document('foo').set({
    'mytime':firestore.SERVER_TIMESTAMP
})
print(result)

This printed out:

update_time {
  seconds: 1523491166
  nanos: 932097000
}

And the value was stored in database as expected.



来源:https://stackoverflow.com/questions/49783651/firebase-firestore-server-timestamp-with-firebase-admin-python-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!