问题
I am using this firebase PHP library
https://github.com/kreait/firebase-php
I have to filter data by keys from user
table.
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__ . self::SECRET_FILE);
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->withDatabaseUri(self::DATABASE_URL)
->create();
$database = $firebase->getDatabase();
$userIds = ['xpCjiz6cuGSx4oBrEUIsn8cqxPy2','xpdXbPu3HdfQ48eZhk2wjUTJtq43','XpdxeLmlvhVABkBYDFyfcVI52Xa2'];
forreach($userIds as $userId){
$values = $database->getReference('users/'.$userId)
->getValue();
echo "<pre>";
print_r($values);
}
I have userids list and fetch all the user records based on random key so how can I fetch all the data in one request?
My above codes works fine to fetch all the user data ,but Problem is I have to send multiple request based on keys. For example If I have 15 userids
so I have to requests 15 times into firebase database to fetch user data.
Here is $userId is random values which is created in each row in table in firebase.
HOW CAN I FETCH ALL USER DATA IN ONE REQUEST BY FILTER MULTIPLE KEYS ?
回答1:
The only way to get multiple (but not all) child nodes with a single request is with a query. But you can't pass multiple IDs in a query.
Simply put: Firebase Realtime Database does not support a WHERE $key IN [key1, key2, key3]
type query that you want to do here. You will have to perform a separate request for each ID.
来源:https://stackoverflow.com/questions/65165908/firebase-query-filter-multiple-keys-by-array-contain-in-php