问题
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