如何使用pyrebase查询? [英] How to use pyrebase query?

查看:47
本文介绍了如何使用pyrebase查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何在python,django和pyrebase中使用查询.查询键的多个值时遇到问题.

I'm learning how to use queries with python, django and pyrebase. I have a problem when querying multiple values of key.

例如:

这是我的数据结构:

    {
    "root": {
        "account": {
            "ACC0001": {
                "id": "ACC0001",
                "create_day": "2020-04-20 16:56:11",
                "create_by": "USE001",
                "brief_name": "AAAAA",
                "status": "active"
            },
            "ACC0002": {
                "id": "ACC0002",
                "create_day": "2020-04-20 16:56:12",
                "create_by": "USE002",
                "brief_name": "BBBBB",
                "status": "inactive"
            },
            "ACC0003": {
                "id": "ACC0003",
                "create_day": "2020-04-20 16:56:13",
                "create_by": "USE003",
                "brief_name": "CCCCC",
                "status": "active"
            },
            "ACC0004": {
                "id": "ACC0004",
                "create_day": "2020-04-20 16:56:14",
                "create_by": "USE004",
                "brief_name": "DDDDD",
                "status": "inactive"
            },
            "ACC0005": {
                "id": "ACC0005",
                "create_day": "2020-04-20 16:56:15",
                "create_by": "USE005",
                "brief_name": "EEEEE",
                "status": "inactive"
            },
            
            ......

            "ACC9999": {
                "id": "ACC9999",
                "create_day": "2020-04-20 16:56:15",
                "create_by": "USE100",
                "brief_name": "FFFFF",
                "status": "active"
            }
        }
    }
}

在SQL中,我像从AAA中选择*,其中D ='active'并且(I ='USE002'或I ='USE003'或I ='USE004'或I ='USE005')一样使用我如何在python,django和pyrebase中获取列表用户的记录?我只得到一个用户而已.我的代码如下:

in SQL i use like "select * from AAA where D = 'active' and (I = 'USE002' or I = 'USE003' or I = 'USE004' or I = 'USE005')" How can i do it in python, django and pyrebase get record of list user ? I just get exactly only one user. My code is below :

    config = {
    'apiKey': "xxxxxx",
    'authDomain': "xxxx.firebaseapp.com",
    'databaseURL': "https://xxxx.firebaseio.com",
    'projectId': "xxxx-92dec",
    'storageBucket': "xxxx-92dec.appspot.com",
    'messagingSenderId': "xxxx598699",
    'appId': "1:xxxxx8699:web:xxxxx5a9e2920ec32e",
    'measurementId': "xxxx360FN"
    }

firebase = pyrebase.initialize_app(config)
database = firebase.database()
// how can get all record of list create_by ['USE001','USE002','USE003'...]
objuser = database.child('account').order_by_child('create_by').equal_to('USE001').get().val()

推荐答案

Firebase实时数据库不允许查询

Firebase Realtime Database doesn't allow querying where equality is checked against a list.

两种实现最终目标的方法:

Two ways to achieve your end goal:

为每个用户使用真值.将数据库更改为这样的内容:

Use truth values for each user. Changing database to something like this:

{
    "root": {
        "account": {
            "ACC0001": {
                "id": "ACC0001",
                "create_day": "2020-04-20 16:56:11",
                "create_by": "USE001",
                "create_by_USE001": true,
                "create_by_USE002": false,
                "create_by_USE003": false,
                "create_by_USE004": false,
                "brief_name": "AAAAA",
                "status": "active"
            },
            "ACC0002": {
                "id": "ACC0002",
                "create_day": "2020-04-20 16:56:12",
                "create_by": "USE002",
                "create_by_USE001": false,
                "create_by_USE002": true,
                "create_by_USE003": false,
                "create_by_USE004": false,
                "brief_name": "BBBBB",
                "status": "inactive"
            },
  ...

更好的方法是使用Firestore,因为它支持在数组中并包含任何

A better approach would be using firestore as it support in and array-contains-any

这篇关于如何使用pyrebase查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆