【问题标题】:Firestore error message: Operator string 'in' is invalidFirestore 错误消息:运算符字符串“in”无效
【发布时间】:2020-01-10 14:35:21
【问题描述】:

我正在使用 python 在 firebase firestore 上执行此查询:

groups = ['AG', 'PA']

docs = db.collection(u'companies').document(company).collection('counts').\
document(count_name).collection('preprocess').\
where('status', '==', 'done').where('statuslayers', '==', 'done').\
where('statuslive', '==', 'created').\
where('load', '==', False).where('group', 'in', groups).\
order_by(u'area').stream()

for doc in docs:
    print(u'{} => {}'.format(doc.id, doc.to_dict()))

触发了这个错误:

运算符字符串“in”无效。有效的选择是:、>=、array_contains。

firebase documentation 页面上的示例非常接近:

cities_ref = db.collection(u'cities')

query = cities_ref.where(u'country', u'in', [u'USA', u'Japan'])
return query

我找不到导致此错误的任何原因,如果我删除 where('group', 'in', groups) 子句,一切正常。

我的谷歌相关包:

  • google-api-core 1.15.0
  • google-api-python-client 1.7.11
  • google-auth 1.10.0
  • google-auth-httplib2 0.0.3
  • 谷歌云 0.34.0
  • google-cloud-core 1.1.0
  • google-cloud-firestore 1.6.1
  • 谷歌云存储 1.24.1
  • google-resumable-media 0.5.0
  • googleapis-common-protos 1.6.0

【问题讨论】:

  • 似乎添加了对此的支持fairly recently,但如果您确定有google-cloud-firestore==1.6.1 ISTM,它应该有该更新,但您可能需要仔细检查它是否确实存在并且您'正在使用你认为你正在使用的包的版本。
  • @Iguananaut 我快速查看了更新日志,似乎IN 是在 1.6.0 中添加的。我不确定为什么它对 Randolfo 不起作用。

标签: python firebase google-cloud-firestore


【解决方案1】:

我用相同的包创建了一个新的虚拟环境并解决了问题,在此之前我尝试更新现有的虚拟环境但没有成功。

新虚拟环境中的包:

  • google-api-core 1.15.0

  • google-api-python-client 1.7.11

  • google-auth 1.10.0

  • google-auth-httplib2 0.0.3

  • google-cloud-core 1.1.0

  • google-cloud-firestore 1.6.1

  • google-cloud-pubsub 1.1.0 google-cloud-storage 1.24.1

  • google-cloud-tasks 1.3.0

  • google-resumable-media 0.5.0

  • googleapis-common-protos 1.6.0

请注意,它们之前是相同的。尽管如此,它还是奏效了。

感谢cmets。

【讨论】:

  • 有时,如果您的环境有点混乱,可能会安装旧版本的软件包,但安装了不正确的元数据(例如,如果软件包在没有先正确卸载的情况下以某种方式重新安装) .如有疑问,不要依赖元数据检查包本身的代码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-15
  • 1970-01-01
  • 2012-02-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多