I am using Appwrite PHP SDK to query a collection that has more than 25 documents. I want to get all the documents in one query, so I tried to set the limit parameter like this:
$query = [
'limit' => 10 // Set the query limit to retrieve only 10 records
];
$staff_member_permissions = $databases->listDocuments('6421819e68517dc04814', '6422a0ea9c35c00f9e6c',$query);
However, this does not work and I still get only 25 documents. How can I get all the documents in one query using Appwrite PHP SDK?
2
Answers
You’re getting only 25 result becuase that’s the default limit.
Reference:
https://appwrite.io/docs/queries
For what I know, you can’t query "unlimited" documents.
If I remember, max limit is 5000…you can pass 5000 as parameter to limit.
Reference:
https://appwrite.io/docs/client/databases?sdk=web-default#databasesListDocuments
As mentioned in another answer there may be a max limit allowed for a single query, but you are also not passing the query parameter in the expected way. From the documentation you should use the
Query
class from the SDK.In this case to set the limit, you may need to instead add
Query::limit(10)
to your queries array, like this:More details on the Queries can be found in the docs.
EDIT: Looking at the issues, there seems to be confusion around how to use queries, you may want to reference this issue where the syntax is a bit different:
You can try increasing that limit, but if you find that you need to retrieve more than the max allowed you will likely have to paginate your request. There is an example of how to do that with the use of limit and offset here. This is the example provided for the Node Client SDK:
You could translate that to PHP and if needed turn it into a loop of some kind to iterate through the results instead of hardcoding the pages.