2011/2/23 Bryan Fink <br...@basho.com>: > On Tue, Feb 22, 2011 at 12:17 PM, francisco treacy > <francisco.tre...@gmail.com> wrote: >>> db.add({ bucket: 'luwak_tld', key_filters: [['starts_with', >>> 'e276814e96e0616eb7c07d3bb744d333']]}).map(function(v) { return [1] }).run() >> POST /mapred >>> { message: 'HTTP error 500: {"error":"bad_json"}' >> , stack: [Getter/Setter] >> , statusCode: 500 >> , notFound: false >> } >> >> but I get "bad_json" errors... Any other bucket works just fine. Why >> won't this work like a regular bucket? > > The data stored in the luwak_tld Riak objects is an Erlang term that > is not directly convertible to JSON. Riak is trying to convert that > object to JSON in order to hand it to the Javascript map function you > specified.
Oh, I think I see. In this case not even the metadata can be translated to JSON. The usual kind of errors about JSON were about the data itself, when attempting to parse it via Riak.mapValuesJson or similar. That's why the supplied function should be written in Erlang. > I recommend using riak_kv_mapreduce:reduce_identity/2 in a reduce > phase, instead of that Javascript map phase to assemble your keylist. > That will avoid the JSON conversion in two ways: it's Erlang native > (so it doesn't need the conversion), and reduce phases don't both with > reading the object from storage anyway. If you really do need to look > at the object before deciding whether or not its key qualifies, you'll > need to code your logic in an Erlang function instead of Javascript. You're right, map actually fetches the object. The use-case here is to get a bunch of keys to delete their values in a subsequent operation. This works (in riak-js): db.add({ bucket: 'luwak_tld', key_filters: [['starts_with', 'e276814e96e0616eb7c07d3bb744d333']]}).reduce({ language: 'erlang', module: 'riak_kv_mapreduce', function: 'reduce_identity', keep: true }).run(/* remove values in this callback */) Thanks, Bryan. Francisco _______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com