首页 > 解决方案 > 上传到 Firestore 会丢失数字的准确性

问题描述

我目前在 Firestore 中有一个数据库,用于将 Discord 用户 ID 与 discord.py 一起存储。我上传它们并在控制台上显示为“数字”类型,我的文档标题是我的用户 ID。然后我还有一个字段是“watcher_id”,这也是我的用户 ID(它们是从同一个变量上传的),但它不正确。该数字丢失了最后 2-3 个值,因此如果我的 id 是671546797994541087它,它将存储为671546797994541000. 这是我上传数据的代码:

caller_id = ctx.message.author.id
doc_ref = db.collection('watcher_list').document(str(caller_id))
doc = doc_ref.get()
if doc.exists:
    doc_data = doc.to_dict()
    uuids_to_watch = doc_data['uuids_to_watch']
    if not uuid in uuids_to_watch:
        uuids_to_watch.append(uuid)
        doc_ref.update({'watcher_id': caller_id, 'watcher': str(ctx.message.author), 'uuids_to_watch': uuids_to_watch})
    else:
        doc_ref.set({'watcher_id': caller_id, 'watcher': str(ctx.message.author), 'uuids_to_watch': [uuid]})

我似乎无法找出导致这种准确性损失的原因,并且想知道它是什么以及如何修复(或在最坏的情况下绕过)它。

提前致谢!

标签: python-3.xfirebasegoogle-cloud-firestorediscord.pygoogle-admin-sdk

解决方案


推荐阅读