.and() issue #1681
Answered
by
dfahlander
TheMenethil
asked this question in
Q&A
.and() issue
#1681
-
Hello, Here is what I have in my DB (for test purposes) :
I want to get a random item between the ones marked "N" in "isDone". To do so, I wrote this :
As you can see, I am struggling with the "and()" condition. I know I don't get something in it but the documentation for it is a bit short. Thank you very much ! |
Beta Was this translation helpful? Give feedback.
Answered by
dfahlander
Mar 5, 2023
Replies: 1 comment 2 replies
-
The doc page is indeed not very expressive. The filter argument should be a callback that takes a database object (value) and returns true or false. Here's an example that might clarify the same intent as your snippet: async function search() {
var count = await db.items.where("isDone").equals("N").count();
var rand = Math.floor(Math.random() * count);
var result = await db.items
.where("isDone").equals("N")
.and(item => item.id === rand) // callback is plain function returning boolean
.toArray(); // still need to do .toArray() at end
return result;
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
dfahlander
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The doc page is indeed not very expressive.
The filter argument should be a callback that takes a database object (value) and returns true or false. Here's an example that might clarify the same intent as your snippet: