Riak.mapValuesJson is returning a string

Brad Corson nucleardragoninc at gmail.com
Fri Jun 8 08:50:42 EDT 2012


Brian,

Thanks for the response, and sorry I couldn't get back to you before this.
I had to change focus to a couple of other projects before I could come
back to my Riak project.

We've solved our problem. Basically, we had to wrap the Riak.mapValuesJson
so that the pertinent part of the map looks like this:

var dats = JSON.parse(Riak.mapValuesJson(value)[0])

I was under the assumption that Riak.mapValuesJson turned the data into a
JSON object, but that wasn't the case for us. Wrapping in a JSON.parse
gives us a JSON object, just like we had originally stored, and lets us use
dot access on the hash.

Thanks again for your response, it helped me to recognize where we went
wrong. We were getting back what LOOKED like expected results, just in a
string format instead of JSON.

Thanks,
Brad



On Wed, May 16, 2012 at 8:48 AM, Brian Shumate <bshumate at basho.com> wrote:

> Hello,
>
> I am running a Riak 1.1.2 rel build from source on OS X 10.7 with Erlang
> R14B04, and just tried a case like yours, but I cannot reproduce your issue:
>
> curl -v -d '{"name": "Brian"}' -H "Content-Type: application/json"
> http://127.0.0.1:8098/riak/test/120000
>
>    * About to connect() to 127.0.0.1 port 8098 (#0)
>    *   Trying 127.0.0.1... connected
>    * Connected to 127.0.0.1 (127.0.0.1) port 8098 (#0)
>    > POST /riak/test/120000 HTTP/1.1
>    > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4
> OpenSSL/0.9.8r zlib/1.2.5
>    > Host: 127.0.0.1:8098
>    > Accept: */*
>    > Content-Type: application/json
>    > Content-Length: 28
>    >
>    < HTTP/1.1 204 No Content
>    < Vary: Accept-Encoding
>    < Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
>    < Date: Sun, 13 May 2012 19:50:49 GMT
>    < Content-Type: application/json
>    < Content-Length: 0
>    <
>    * Connection #0 to host 127.0.0.1 left intact
>    * Closing connection #0
>
> curl -i localhost:8098/riak/test/120000
>
>    HTTP/1.1 200 OK
>    X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fvpv4P+QwZTImMfKMLNH5SRfFgA=
>    Vary: Accept-Encoding
>    Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
>    Link: </riak/test>; rel="up"
>    Last-Modified: Sun, 13 May 2012 19:50:49 GMT
>    ETag: "hsUPQi54y1EKeXVazb3fl"
>    Date: Sun, 13 May 2012 19:50:56 GMT
>    Content-Type: application/json
>    Content-Length: 28
>
>    {"name": "Brian"}%
>
> curl -v -d '{"inputs":[["test", "120000"]],
> "query":[{"map":{"language":"javascript", "source":"function(value,
> keyData, arg) { var dats = Riak.mapValuesJson(value)[0]; return [typeof
> dats];}"}}]}' -H "Content-Type: application/json"
> http://127.0.0.1:8098/mapred
>
>    * About to connect() to 127.0.0.1 port 8098 (#0)
>    *   Trying 127.0.0.1... connected
>    * Connected to 127.0.0.1 (127.0.0.1) port 8098 (#0)
>    > POST /mapred HTTP/1.1
>    > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4
> OpenSSL/0.9.8r zlib/1.2.5
>    > Host: 127.0.0.1:8098
>    > Accept: */*
>    > Content-Type: application/json
>    > Content-Length: 184
>    >
>    < HTTP/1.1 200 OK
>    < Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
>    < Date: Sun, 13 May 2012 19:52:28 GMT
>    < Content-Type: application/json
>    < Content-Length: 10
>    <
>    * Connection #0 to host 127.0.0.1 left intact
>    * Closing connection #0
>    ["object"]%
>
> As you can see above, I get the expected results.
>
> What version of Riak are you using? What does the full (with -v) output of
> storing an object in your case look like?
>
> Regards,
>
> Brian
>
> On May 16, 2012, at 8:40 AM, kodeblok wrote:
>
> > Does anyone have any thoughts on this? I'm unable to perform MapReduce
> > queries.
> >
> > Thanks
> >
> > --
> > View this message in context:
> http://riak-users.197444.n3.nabble.com/Riak-mapValuesJson-is-returning-a-string-tp3942213p3996979.html
> > Sent from the Riak Users mailing list archive at Nabble.com.
> >
> > _______________________________________________
> > riak-users mailing list
> > riak-users at lists.basho.com
> > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20120608/465db287/attachment.html>


More information about the riak-users mailing list