Skip to content
Luke Bakken edited this page Oct 5, 2016 · 1 revision

Saving Map Results

Source File on GitHub

This Erlang function will save the output of a map to a bucket and key (passed by argument).

-module(reduce_functions).

%%Function assumes JSON values
-export([save_reduce/2]).

%%Arg is a [bucket, key] combination
save_reduce([Data | _], [Bucket, Key]) ->
    {ok, C} = riak:local_client(),
    Json = iolist_to_binary(mochijson2:encode(Data)),
    Object = riak_object:new(Bucket, Key, Json, "application/json"),
    C:put(Object, 1),
    [];
save_reduce(_, _) ->
    [].