Closed LeiYangGH closed 2 years ago
Hey @LeiYangGH,
I think you can use the map()
query operator here:
db.search(where('num').map(int) > 0)
This assume that all num
fields are numbers or strings that represent numbers. Otherwise, you can cast to a default value like NaN
:
db.search(where('num').map(lambda x: int(x) if isinstance(x, int) or x.isnumeric() else float('nan')) > 0)
Does that work for you?
i think map
works, thanks!
Awesome 🙂
I have a field
foo
which type sometimes are int, but sometimes are string(of numbers). If I compare directly, I will get error such asI tried convert to int,
int(q.foo) <= given_int
but gotI searched document and found test function can determine the field type
But this way code seems too verbose, is there any simpler syntax to convert type before query?