带有 firebase-admin python sdk 的 Firebase Firestore 服务器时间戳
Firebase Firestore Server Timestamp with firebase-admin python sdk
firebase-admin python sdk 有添加服务器时间戳的方法吗?
我试试:
firestore.SERVER_TIMESTAMP
firestore.constants.SERVER_TIMESTAMP
但是,我得到了这个例外:
TypeError: ('Cannot convert to a Firestore Value', <object object at 0x10380fc20>, 'Invalid type', <class 'object'>)
firestore.SERVER_TIMESTAMP
对我有用。这是完整的示例:
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
}
并且该值按预期存储在数据库中。
firebase-admin python sdk 有添加服务器时间戳的方法吗? 我试试:
firestore.SERVER_TIMESTAMP
firestore.constants.SERVER_TIMESTAMP
但是,我得到了这个例外:
TypeError: ('Cannot convert to a Firestore Value', <object object at 0x10380fc20>, 'Invalid type', <class 'object'>)
firestore.SERVER_TIMESTAMP
对我有用。这是完整的示例:
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
}
并且该值按预期存储在数据库中。