I have a collection of around 10000 items. I need to query a document with the following criterion : Give me a document whose reference attribute is not present in this list. This, I can do with "notequal" method. Here is my question : this condition will be true of many documents : how can I do it so that it doesn't always give me the first document, I kinda need it to pick "randomly" among the 10000... not the first one. Is there a way ? Or do I have to retrieve ALL documents and then shuffle it locally ?
There is no random query at the moment. You might want to 👍 this issue: https://github.com/appwrite/appwrite/issues/5205
That said, you could try using a random offset
What is a random offset ?
I added comment on the issue link you gave me
Create a random number and then pass that in an offset query
Did you 👍 the issue?
yes I just did. So If I need a document in a collection respecting a certain condition : example : any item whose reference isn"'t equal to "CEA1" : my query will download ALL the documents, of just the first one ? How can I tell Appwrite to give me the 10th document respecting the condition ?
Have you tried looking into offset queries?
No I didn't know what it was, or that it existed 😉
Try searching the docs
It gives answers by "skipping" some documents ?
I see one line in the docs for that
OK I see... but for that I would need to know how many documents respect my condition. Is there a way to do this ?
You can query without the offset and include a limit. Then check the total in the response
But I fear if I do that, it will keep picking items in the first part of the collection...
How and why?
Hmm : My bank has 10000 questions used to create a language test. A question is based on a document (a text, an audio...). In the question item : there is a reference that indicates the reference of the document. In the bank : there are many questions based on a same document. But for a test, a document can only be used once. So when student takes the test : it picks a first question. This means for the following questions the document of the first one can no longer be used. So it means : the next question should be picked in the bank with document not equal to.... . A test has 15 questions total. So I fear that every time the student starts a new test : it's always made up of questions picked in the beginning of the list. (Never Item n°8000 for example, because there will always be items possible before).
You're going to be filtering with queries so what's the problem?
I guess I must not understand how it works then. Sorry
Read the docs and try it out. That would be the best way to figure it out. Feel free to ask follow up questions if you have any
If I query a document with this condition : one attribute not equal "CEA1". Then what does it do exactly ? It scans the collection until it finds a document respecting the condition ? is this correct ?
and then downloads the document, correct ?
Try it
Recommended threads
- Weird permission failure
when creating an account I use following methods: ``` Future<void> register(String email, String password, String username) async { final user = await accoun...
- Flutter Android oAuth is no more working
I currently don't get the oAuth login to work in flutter android. it works on ios and on web. but when try to use it on Android, i get to the point where the ca...
- Relation Question
How do I create a relation from table y to an others x.$id. in my example I have a users table where I use Appwrites unique User IDs and I want other tables fo...