Back to top

    ReQL command: add

    Command syntax

    value.add(value[, value, ...]) → value

    time.add(number[, number, ...]) → time

    Description

    Sum two or more numbers, or concatenate two or more strings or arrays.

    The add command can be called in either prefix or infix form; both forms are equivalent. Note that ReQL will not perform type coercion. You cannot, for example, add a string and a number together.

    Example: It’s as easy as 2 + 2 = 4.

    r.expr(2).add(2).run(conn);
    
    // Result:
    4
    

    Example: Concatenate strings.

    r.expr("foo").add("bar", "baz").run(conn);
    
    // Result:
    "foobarbaz"
    

    Example: Concatenate arrays.

    r.expr(["foo", "bar"]).add(["buzz"]).run(conn);
    
    // Result:
    [ "foo", "bar", "buzz" ]
    

    Example: Create a date one year from now.

    r.now().add(365*24*60*60).run(conn);
    

    Example: Use args with add to sum multiple values.

    int[] vals = { 10, 20, 30 };
    r.add(r.args(vals)).run(conn);
    
    // Result:
    60
    

    Example: Concatenate an array of strings with args.

    String[] vals = { "foo", "bar", "buzz" };
    r.add(r.args(vals)).run(conn);
    
    // Result:
    "foobarbuzz"
    

    Get more help

    Couldn't find what you were looking for?