Web Dev Cody
Web Dev Cody13mo ago

Possible to do an OR in withIndex

let's say I want to find all messages with isRead false or undefined, is that possible when doing withIndex?
3 Replies
lee
lee13mo ago
A withIndex query returns a contiguous range of documents, when the documents are sorted by the index field. So if you want to do an OR you can do two withIndex queries and merge the results. In this very specific case, if the field can be only undefined, false, or true, you can use the ordering of undefined < false < true to query with q.lte("field", false) or q.lt("field", true) because that's a contiguous range
Web Dev Cody
Web Dev CodyOP13mo ago
how do you know that's the ordering? or how would I determine what the sort order might be for various values?
lee
lee13mo ago
i don't think it's documented very well, so i would create documents with the values you want and see what the order is with .withIndex("by_field").collect() . also i can tell you the ordering between types: undefined<null<int64<float64<bool<string<bytes<array<object. within each type, the ordering should be intuitive, matching what you would get from a < symbol in most languages.

Did you find this page helpful?