【问题标题】:InvalidArgument: 400 Cannot convert an array value in an array valueInvalidArgument: 400 无法将数组值转换为数组值
【发布时间】:2021-09-30 18:00:32
【问题描述】:

我有一个字典,其中包含两个列表,显示为:dictionary =

{'Position': [['Teaching', '10'],
  ['Supervisor', '3']]],
 'Major': [['Arts', '1'],
  ['Accounting', '6']]}

我想将这些添加到 firestore,其中列表的第一个元素是“字段名称”,第二个元素是值。

输出应如下所示:

Position (map)
         Teaching : 10
         Supervisor : 3
Major (map)
         Arts : 1
         Accounting:6

到目前为止我的代码:

default = {'Position':{}, 'Major':{}}
db.collection(u'coll').document(u'info').collection(u'colname').set(default)


storeReference = db.collection(u'coll').document(u'info').collection(u'colname')

storeReference.set({dictionaryy}, merge=True)

错误:

InvalidArgument: 400 无法将数组值转换为数组值。

如何解决?

【问题讨论】:

    标签: python google-cloud-firestore


    【解决方案1】:

    不应该是update({dictionary}, merge=True)而不是set吗?

    据我了解,set 用于当项目尚不存在时,但我相信您已经使用 set(default) 创建了它...

    我看到storeReference 引用了集合而不是文档。

    最后,我认为您应该阅读this,因为它来自去年,并且仍然适用。它应该是{['Teaching','10'],['Supervisor','3']} 而不是[['Teaching','10'],['Supervisor','3']]。就是把数组值转换成数组值的意思(把数组中的值转换成数组内自己的数组,没有嵌套)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多