Back

[SOLVED] Code to clear database

  • 0
  • Self Hosted
  • Databases
Drake
22 Jul, 2023, 05:41

Put list documents in a loop until you don't have any documents left

TL;DR
Solution: To clear the database, use the code provided in the discussion. It is suggested to include a limit parameter and use pagination for better performance. The default limit is 25 documents, but it can be changed by specifying the limit in the query. If you want to surpass the 25 document limit, you can put the list documents function in a loop until there are no remaining documents.
Hemish11
22 Jul, 2023, 05:42

So there isnt any way to surpass the 25 documents limit?

Drake
22 Jul, 2023, 05:42

Btw, you don't need to await each delete

Drake
22 Jul, 2023, 05:43

Before version 1.3, the maximum limit is 100. After that, you can set some high number, but it's still good to paginate/do it in chunks

Hemish11
22 Jul, 2023, 05:44

Got it, for my frontend im using pagination

Hemish11
22 Jul, 2023, 05:44

Also, how can i change that limit?

Drake
22 Jul, 2023, 05:50
Hemish11
22 Jul, 2023, 06:13

Got it thanks a lot

Drake
22 Jul, 2023, 06:17

[SOLVED] Code to clear database

D5
22 Jul, 2023, 10:24

It is specified in docs πŸ€”

Drake
22 Jul, 2023, 15:02

Only on the queries docs for the limit query, right? But if I'm only looking at the list documents API, it's not there and I'd have to dig in a bit before finding out of the default limit.

Before, when we had limit as a param, it was much more apparent. Now, it's kind of hidden away

D5
22 Jul, 2023, 15:14

Yes, true

VincentGe
24 Jul, 2023, 01:36

🀣 For DX, it's basically a choice.

For discoverability, force them to provide the limit ever single time does this. Otherwise we'd have to rely on them reading docs.

A possibility is to just add this information in the return object:

TypeScript
{
    "total": 25,
    "limit": 25,
    "offset": whatever,
    "other_stuff": wejrk,
    "documents": [
        {
            "$id": "5e5ea5c16897e",
            "$collectionId": "5e5ea5c15117e",
            "$databaseId": "5e5ea5c15117e",
            "$createdAt": "2020-10-15T06:38:00.000+00:00",
            "$updatedAt": "2020-10-15T06:38:00.000+00:00",
            "$permissions": [
                "read(\"any\")"
            ]
        }
    ]
}
VincentGe
24 Jul, 2023, 01:37

But my honest opinion is that long term this is just a quirk they should have to learn πŸ˜… I feel like every framework has a few. We can make it easier with better docs + hinting

VincentGe
24 Jul, 2023, 01:38

The other extreme option is to basically have no limit by default

Drake
24 Jul, 2023, 01:38

Docs is fine to me, but it's just a little hidden right now

VincentGe
24 Jul, 2023, 01:38

And be like SQL

VincentGe
24 Jul, 2023, 01:38

where the default behavior is as expected, literally no limit and it just crashes your terminal if you try to select * from BIG_DATA_LAKE

VincentGe
24 Jul, 2023, 01:38

LOL

VincentGe
24 Jul, 2023, 01:39

πŸ˜… I feel like we can probably show that we requested up to x objects and y objects were returned

VincentGe
24 Jul, 2023, 01:39

That would offer a hint

VincentGe
24 Jul, 2023, 01:40

The most confusing part is "total"

VincentGe
24 Jul, 2023, 01:40

total of what?

VincentGe
24 Jul, 2023, 01:40

The entire DB?

VincentGe
24 Jul, 2023, 01:40

The entire collection?

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more