如何使用Python的SDK在Firestore上编写位置、引用和时间戳数据类型?

2024-09-30 22:27:34 发布

您现在位置:Python中文网/ 问答频道 /正文

文档甚至解释了如何编写以下数据类型:

data = {
  u'stringExample': u'Hello, World!',
  u'booleanExample': True,
  u'numberExample': 3.14159265,
  u'dateExample': datetime.datetime.now(),
  u'arrayExample': [5, True, u'hello'],
  u'nullExample': None,
  u'objectExample': {
    u'a': 5,
    u'b': True
  }
}

我正在将mongodb集合迁移到FireStore中。在

这是我目前为止的代码:

^{pr2}$

我想写一个文件与参考和位置字段加上一个自定义日期。在


Tags: 文档truehelloworlddatadatetimenow数据类型
1条回答
网友
1楼 · 发布于 2024-09-30 22:27:34

在获得响应(res)和初始化字典(文档要写入)后:

Document_to_write['date_type'] = datetime.datetime.strptime(res['created'], "date format in string")
Document_to_write['reference_type'] = db.document(u'Collection_Name/'+res['collection_id'])
Document_to_write['location_type'] = firestore.GeoPoint(res['latitude'], res['longitude'])

按此操作可使用选定的方法保存。在

相关问题 更多 >