我正在学习如何在python、django和pyrebase中使用查询。查询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中,我使用like "select * from AAA where D= 'active‘and (I = 'USE002’or i= 'USE003‘or i= 'USE004’or i= 'USE005')“在python、django和pyrebase中如何获取列表用户的记录?我只有一个用户。我的代码如下:
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()发布于 2020-07-10 17:13:21
Firebase实时数据库不允许查询where equality is checked against a list。
实现最终目标的两种方法:
对每个用户使用真值。将数据库更改为如下所示:
{
"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,因为它支持in and array-contains-any
https://stackoverflow.com/questions/62751722
复制相似问题