Search code examples
bit-manipulationbitwise-operatorsrethinkdbbitwise-and

Rethink DB Bitwise comparison


I'm trying to filter a rethinkdb selection based on some bits in a field I've tried doing

r.db("db").table("table").filter(r.expr(r.row("flags") & 64).ne(0))
// and
r.db("db").table("table").filter(r.row("flags") & 64)

64 being the one to test, with no luck, nothing is returned. I've tried doing the tests without calling rows, and it works just fine

r.db("db").table("table").filter(114 & 64)
// or
r.db("db").table("table").filter(r.expr(114 & 64).ne(0))

that returns either all the entries, or none. I want to only get the entries where the bit test does not equal 0


Solution

  • rethinkdb does not have the bitwise AND operator by default, but it can execute arbitrary javascript as filter function as follows:

    r.db("db").table("table").filter(
       r.js('(function (row) { return (row.flags & 64) != 0; })')
    )