contains

ReQL command: contains

Command syntax

sequence.contains([value | predicate_function, ...]) → bool
r.contains(sequence, [value | predicate_function, ...]) → bool

Description

When called with values, returns True if a sequence contains all the specified values. When called with predicate functions, returns True if for each predicate there exists at least one element of the stream where that predicate returns True.

Values and predicates may be mixed freely in the argument list.

Example: Has Iron Man ever fought Superman?

r.table('marvel').get('ironman')['opponents'].contains('superman').run(conn)

Example: Has Iron Man ever defeated Superman in battle?

r.table('marvel').get('ironman')['battles'].contains(lambda battle:
    (battle['winner'] == 'ironman') & (battle['loser'] == 'superman')
).run(conn)

Example: Use contains with a predicate function to simulate an or. Return the Marvel superheroes who live in Detroit, Chicago or Hoboken.

r.table('marvel').filter(
    lambda hero: r.expr(['Detroit', 'Chicago', 'Hoboken']).contains(hero['city'])
).run(conn)

Related commands

Get more help

Couldn't find what you were looking for?

© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/python/contains/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部