ibrahimyaacob
ibrahimyaacob9mo ago

How do i query the adjacent records

i have a table with field score, given a record with score 10, how do query the other record nearest to 10, example, 10, 9, 11. you got the idea.
1 Reply
sshader
sshader9mo ago
If you define an index on score, then you can do something like db.query("myTable").withIndex("by_score", q => q.gt("score", 10)) (and another query for less than). If your goal is to return the 5 closest, you could fetch 5 documents on either side with your queries and then in JavaScript return the 5 that are closest out of the ones you fetched.

Did you find this page helpful?