带有firebase-admin python sdk的Firebase Firestore Server时间戳 [英] Firebase Firestore Server Timestamp with firebase-admin python sdk
本文介绍了带有firebase-admin python sdk的Firebase Firestore Server时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有一种方法可以在 firebase-admin python sdk 中添加服务器时间戳? 我尝试:
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'>)
推荐答案
firestore.SERVER_TIMESTAMP
为我工作.这是完整的示例:
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)
此打印输出:
update_time {
seconds: 1523491166
nanos: 932097000
}
该值已按预期存储在数据库中.
And the value was stored in database as expected.
这篇关于带有firebase-admin python sdk的Firebase Firestore Server时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文