Skip to content

Latest commit

 

History

History
44 lines (30 loc) · 923 Bytes

File metadata and controls

44 lines (30 loc) · 923 Bytes
layout language permalink command
api-command
Python
api/python/js/
js

Command syntax

{% apibody %} r.js(js_string[, timeout=]) → value {% endapibody %}

Description

Create a javascript expression.

Example: Concatenate two strings using JavaScript.

timeout is the number of seconds before r.js times out. The default value is 5 seconds.

{% infobox %} Whenever possible, you should use native ReQL commands rather than r.js for better performance. {% endinfobox %}

r.js("'str1' + 'str2'").run(conn)

Example: Select all documents where the 'magazines' field is greater than 5 by running JavaScript on the server.

r.table('marvel').filter(
    r.js('(function (row) { return row.magazines.length > 5; })')
).run(conn)

Example: You may also specify a timeout in seconds (defaults to 5).

r.js('while(true) {}', timeout=1.3).run(conn)