Firebase Firestore Server Timestamp with firebase-admin python sdk

后端 未结 1 1401
野性不改
野性不改 2021-01-21 14:51

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

firestore.SERVER_TIMESTAMP
firestore.constants.SERVER_TIMESTAMP


        
相关标签:
1条回答
  • 2021-01-21 15:52

    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.

    0 讨论(0)
提交回复
热议问题