ReQL command: ~, not_
Command syntax
bool.not_() → bool
not_(bool) → bool
(~bool) → bool
Description
Compute the logical inverse (not) of an expression.
not_ can be called either via method chaining, immediately after an expression that evaluates as a boolean value, or by passing the expression as a parameter to not_. All values that are not False or None will be converted to True.
You may also use ~ as a shorthand operator.
Example: Not true is false.
r.not_(True).run(conn)
r.expr(True).not_().run(conn)
(~r.expr(True)).run(conn)
These evaluate to false.
Note that when using ~ the expression is wrapped in parentheses. Without this, Python will evaluate r.expr(True) first rather than using the ReQL operator and return an incorrect value. (~True evaluates to −2 in Python.)
Example: Return all the users that do not have a “flag” field.
r.table('users').filter(
lambda users: (~users.has_fields('flag'))
).run(conn)
Example: As above, but prefix-style.
r.table('users').filter(
lambda users: r.not_(users.has_fields('flag'))
).run(conn)
Get more help
Couldn't find what you were looking for?
- Ask a question on Stack Overflow
- Chat with us and our community on Slack
- Talk to the team on IRC on #rethinkdb@freenode.net — via Webchat
- Ping @rethinkdb on Twitter
- Post an issue on the documentation issue tracker on GitHub
Contribute: edit this page or open an issue