Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (46 sloc) 1.6 KB
layout language permalink command io related_commands
api-command
JavaScript
api/javascript/contains/
contains
sequence
bool
map concat_map group
map/
concat_map/
group/

Command syntax

{% apibody %} sequence.contains([value | predicate_function, ...]) → bool r.contains(sequence, [value | predicate_function, ...]) → bool {% endapibody %}

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, callback);

Example: Has Iron Man ever defeated Superman in battle?

r.table('marvel').get('ironman')('battles').contains(function (battle) {
    return battle('winner').eq('ironman').and(battle('loser').eq('superman'));
}).run(conn, callback);

Example: Return all heroes who have fought both Loki and the Hulk.

r.table('marvel').filter(function (hero) {
  return hero('opponents').contains('loki', 'hulk');
}).run(conn, callback);

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(function(hero) {
    return r.expr(['Detroit', 'Chicago', 'Hoboken']).contains(hero('city'))
}).run(conn, callback);
You can’t perform that action at this time.