简体   繁体   English

在 firebase_admin 上使用“where”查询时无法过滤数据

[英]cannot filter data when using `where` query on firebase_admin

I want to get data for ages over 30 using code我想使用代码获取 30 岁以上的数据

db.collection('persons').where(u"age", u">=", 30).get()

with a data structure like the following具有如下数据结构在此处输入图像描述

but the database does not return any data, just an empty list但数据库不返回任何数据,只是一个空列表

The problem comes from the fact that your age field is of type String (it's shown between double quotes in the console), while your query is using a Number (the third parameter passed to the where() method).问题在于您的age字段是字符串类型(在控制台中显示在双引号之间),而您的查询使用的是数字(传递给where()方法的第三个参数)。

You don't show how you create the doc but it's there that you have to take care of writing this field with the desired type, ie Number in your case.你没有展示你是如何创建文档的,但在那里你必须注意用所需的类型编写这个字段,即你的情况下的数字。

PS: there are probably two typos in your code with the where() method: there are two extra u . PS:使用where()方法的代码中可能有两个拼写错误:有两个额外的u

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用带有 get() 的 firebase_admin 查询 firestore 文档 - How do I query a firestore document using firebase_admin with get() 为什么 firebase_admin 在运行多进程时无法解析 - Why firebase_admin doesn't resolve when running multiprocesses 如何在 python 上调试 firebase_admin - How to debug firebase_admin on python 如何使用 firebase_admin 从 python 中的 firebase 存储中下载文件 - How to download file from firebase storage in python using firebase_admin Python Firebase 问题没有名为 firebase_admin 的模块 - Python Firebase issue No module named firebase_admin 我的 firebase_admin 配置可以很好地验证用户吗? - My configuration of firebase_admin is good to authenticate users? Firestore AttributeError:模块“firebase_admin”没有属性“firestore” - Firestore AttributeError: module 'firebase_admin' has no attribute 'firestore' firebase_admin auth.verify_id_token 很慢 - firebase_admin auth.verify_id_token is very slow 如何使用带有 FieldPat.documentId 的 where 子句过滤 firebase 数据 - How to filter firebase data using a where clause with FieldPat.documentId 如何在同一项目中为 firebase_admin 应用程序的每个实例使用模拟器 - How to use an emulator for each instance of firebase_admin app, in the same project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM