Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将常量值分配给名为服务器函数firestore.server.TIMESTAMP的变量python_Python 3.x_Google Cloud Firestore - Fatal编程技术网

Python 3.x 将常量值分配给名为服务器函数firestore.server.TIMESTAMP的变量python

Python 3.x 将常量值分配给名为服务器函数firestore.server.TIMESTAMP的变量python,python-3.x,google-cloud-firestore,Python 3.x,Google Cloud Firestore,我正在尝试为Firestore中的几个字段分配相同的时间戳。我正在使用python 3.7 我生成时间戳的代码如下 current_system_timestamp = firestore.SERVER_TIMESTAMP 我正在使用当前的\u系统\u时间戳更新Firestore中的字段。像这样 channel_id_doc_ref.set({ 'timestamp' : current_system_timestamp,

我正在尝试为Firestore中的几个字段分配相同的时间戳。我正在使用python 3.7

我生成时间戳的代码如下

current_system_timestamp    = firestore.SERVER_TIMESTAMP
我正在使用当前的\u系统\u时间戳更新Firestore中的字段。像这样

   channel_id_doc_ref.set({
                    'timestamp'  : current_system_timestamp,
                    'initiator_name'       : user_name
                })

 notes_doc_ref.set({
            'note'         : chat_note
            'timestamp_entered'     : current_system_timestamp
        })

不幸的是,在Firestore中设置的两个时间戳值是不同的,相差毫秒。这让我相信,我需要在python中将当前系统时间戳声明为常量。我该怎么做

firestore.SERVER\u TIMESTAMP
在发送请求后获取firestore服务器上的最终值。在编写文档时,客户端上的值未知。由于您的客户机代码在两个不同的时间编写两个不同的文档,您可以预期最终的时间戳是不同的,因为它们不会在完全相同的时间到达服务器

分配
firestore.SERVER\u时间戳将不会更改任何内容。如果您要求两个文档具有相同的时间戳,则必须编写特殊代码来实现。相反,您可以编写第一个文档,然后立即将其读回,从中捕获最后的时间戳,然后将其用作未来文档中的时间戳字段