EzDevInfo.com

riak-js

Riak client for Javascript riak-js | node.js riak client

NodeJS client library for riak

I am starting a project that will use riak with nodejs. I see number of community supported libraries in nodejs for riak in basho site -- http://docs.basho.com/riak/latest/dev/using/libraries/#Basho-Supported-Libraries . Can anybody point me to any research or experience with any of these and specific advantage / disadvantage faced while using any of these libraries ? I shall do my research in parallel and will update the group with results.


Source: (StackOverflow)

Using Riak.js / Riak, how do I do an "AND" select?

I am trying to determine the existence of an object to decide whether to create a new object with a new key or to update an existing object. The goal here is to match on two Secondary Indexes.

db.query(bucket, {end: null, definition_id: id}, function(err, data) {
    if (err) {
        res.send(err);
    } else {
        if (data.length === 0) {
            // write new obj
        } else {
            // add to current obj
        }
    }
});

If there is an easy way to do this with the HTTP API I would be game for that, too, just can't seem to find it in the docs.

Thanks.


Source: (StackOverflow)

Advertisements

backbone: how to apply the correct filter to a collection of objects

I have a node application that binds url queries to riak indices. Salient express.js code, which uses express.router:

  router.get('/.:format?', (req, res, next)->
        res.dbStartTime = new Date()
        collection = new Backbone.Collection([], {model: ModelCtor})
        collection.url = modelProto.urlRoot
        if Object.keys(req.query).length > 0
            collection.query = req.query

        collection.fetch({query: req.query}).then(->
            sendList(req, res, next, collection)
        , (err)->
            next(err)
        )
    )

This, plus some other creative mounting, allows me to do things like localhost:5000/people?name=Abraham, which returns a view associated with a collection of people who are named Abraham.

I can complete the same pattern for all binaries, but when I try to do something using Riak integer indices it no longer works, i.e. localhost:5000/people?age=15. Appreciating that I'll probably have to explain other elements of my code, what is the right way to structure a url query so that it will match up with integer indices in Riak?


Source: (StackOverflow)

How can I get riak-js to return walked objects?

I'm using a Riak database from Node via riak-js. I have two buckets: invites and events. Invites has a link to events. I'd really like to retrieve the invite object and the corresponding event object in one query. To this end, I've tried this:

db.walk("invites", inviteKey, 
[{ bucket: 'events', tag: 'event', keep: true}], 
   function (err, result, meta) { /* ... */ });

But that just gives me the Event corresponding to the invite, it doesn't give me the Invite. I'm guessing the keep attribute is either not meant to go there, or is being ignored for some reason. Is there a way to do this? The Riak-js documentation is difficult.


Source: (StackOverflow)

Riak-How to filter objects of one bucket based on another bucket?

I am using a 3 node Riak Cluster with a number of buckets. I have a bucket called user_account which has user information like name, address etc.

user_account = {"id" => 1,"name"=>"abc", "address"=>"xyz"}

There is another bucket user_metadata which updates this data. A record in it looks like:

user_metadata = {"id" => 1, "created_at"=>"20140304", "updated_at" => "20140304"}

Both the buckets have the same key which is the id. I want to run map_reduce on bucket user_account for all the keys which are updated within a date range in user_metadata. Is there a way I can do this, also currently there is no index for updated_at key in user_metadata bucket.


Source: (StackOverflow)

Dynamically setting bucket time-to-live on Riak and Bitcask with riak-js

Is it possible to change the expiry_secs parameter on bitcask buckets dynamically? CallingĀ riak.saveBucket('bucket', {expiry_secs: 60}); will cause subsequent calls of riak.getBucket('bucket') to report 60 as the key ttl, but keys never seem to expire.

Is there a separate setting that needs to be modified, or can expiry_secs only be set in Riak's app.config and not from a client application?


Source: (StackOverflow)

Querying a Riak DB by a Subkey

I'm using riak-js and node.js

If I have a document as follows:

 { 'skey1': 'val1',
   'skey2': 'val2',
     ......,
   'skeyn': 'valn'
  }

How can I return a document that has skey2 = 'val2'? How would this be done in node.js / riak-js?


Source: (StackOverflow)

Riak like REST service with Angular.js client

hi i use Riak(http://basho.com/riak/) as rest service and Angular on client, when i try so use method "PUT" then first request is OPTION, but Riak doesn't know how to properly respond for this. I found some clients but all of them are made to run on server, not sure about Node.js client like this http://riak-js.org/ can i make it working from web client?

Maybe Riak was not meant to work with web clients directly, then i'll try something else.


Source: (StackOverflow)

riak-js key_filters string_to_int status code 500

I could not make key_filter work with string_to_int transformation always get status code 500.

My object structure is the following:

{ "style": "double", "capacity": 6 }

My map function:

var client = require('riak-js')
    .getClient({host: "localhost", port: "10018"}),
    bucket = 'rooms';

client.mapreduce
.add({
    bucket: bucket, 
    key_filters: [["string_to_int"], ["and", [["greater_than", 1000]], [["less_than", 3000]]]]
})
.map('Riak.mapValuesJson')
.run(function(err, data){
    if (err) {
        console.log(JSON.stringify(err));
    } else {
        console.log(JSON.stringify(data));
    }
});

Response:

{ "message": "[object Object]", "statusCode": 500 }

P.S.

  • Riak 1.4.7
  • Erlang R15B01
  • nodejs v0.10.25
  • riak-js 0.10.2

UPDATE here are my request for keys and response:

curl http://mydomain.com:10018/riak/rooms?keys=true

{"props":{"name":"rooms","allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun": {"mod":"riak_core_util","fun":"chash_std_keyfun"},"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","small_vclock":50,"w":"quorum","young_vclock":20},"keys":["6774","2205","6515","3812","2164","8677","3637","8701","2868","7249","3118","9781","4217","8432","4250","7551","7672","8736","7933"...

UPDATE 2 I did request with curl:

curl -v -X POST -H "Content-Type: application/json" http://mydomain.com:10018/mapred -d '{"inputs": {"bucket":"rooms","key_filters":[["string_to_int"],["and",[["greater_than",1000]],[["less_than",3000]]]]}, "query":[{"map":{"language":"javascript","name":"Riak.mapValuesJson"}}]}'

and got result:

{ "phase":"listkeys", "error":"function_clause", 
    "input":"{cover,[{1392993748081016843912887106182707253109560705024, 1392993748081016843912887106182707253109560705024]}],
        {<<\"rooms\">>,[{riak_kv_mapred_filters,string_to_int,[]},{riak_kv_mapred_filters,logical_and,[[[<<\"greater_than\">>,1000]],[[<<\"less_than\">>,3000]]]}]}}",
        "type":"error","stack":"[{riak_kv_pipe_listkeys,keysend,[error,{worker_crash,{badarg,[{erlang,list_to_integer,
    [\"5Ll5Gl3L61JX2mxYUvht6OMca4d\"],[]},{riak_kv_mapred_filters,'-string_to_int/1-fun-0-',1,
    [{file,\"src/riak_kv_mapred_filters.erl\"},
    {line,84}]},
    {lists,foldl,3,[{file,\"lists.erl\"},{line,1197}]},
    {riak_kv_coverage_filter,'-compose/2-fun-1-',2,[{file,\"src/riak_kv_coverage_filter.erl\"},{line,137}]},
    {riak_kv_vnode,'-fold_fun/3-fun-3-',5,[{file,\"src/riak_kv_vnode.erl\"},{line,1342}]},
    {bitcask_nifs,keydir_fold_cont,4,...},...]},...},...],...},...]"
}

Source: (StackOverflow)