python-3.x - 在 Firestore 中创建时指定数字字段值?
问题描述
我想在创建时在 firestore 数据库中创建一个整数值。但是,我传递的每个变量都会变成一个字符串。
这就是我所拥有的:
next_group_id = self.GetNextGroupId() #returns int value
try:
# get the document
doc_ref = self._db.collection(GROUPS).document(next_group_id)
# create a new document
# this gets created as a string in firestore
doc_ref.set({
u'Group Id': next_group_id,
})
print("Created Group '{}'.".format(group._group_name))
except:
print("Possible firestore error has accord - unable to create group")
解决方案
原来你不能用这样的整数搜索文档:
doc_ref = self._db.collection(GROUPS).document(next_group_id)
所以我只是转换成一个字符串,它工作正常......
doc_ref = self._db.collection(GROUPS).document(str(next_group_id))
推荐阅读
- laravel - 如何使用 Tucker-Eric/EloquentFilter Laravel
- javascript - 我想从我的前端 JavaScript 调用节点(服务端)中的一个函数
- html - 如何循环播放 CSS 动画?
- c# - 如何从UserControl获取数据到Form?C# WinForms 和 SQLite
- node.js - 使用编写的服务器实现 RPC 客户端 Node.js
- nginx - ApolloClient 3 并发 30 graphql 订阅调用从 nginx 返回 502
- oracle - 如何将 .JSON 文件导入 Oracle SQL Developer
- laravel - Laravel groupBy - 如何选择按一列分组的多列
- dialogflow-es - 如何延迟 DialogFlow 响应?
- google-chrome-extension - 如何检查当前 URL Chrome 扩展和 JS