var riakObj = {mykey1: "myvalue1"};
var data = {
key: 'my_key',
bucket: 'my_bucket',
type: 'my_bucket_type',
content = {
'value': JSON.stringify(riakObj),
content_type: 'application/json'
},
return_body: true
// vclock = vclock // Use the vclock if you have it
};
client.put(data, function(e,d) {
if (e) {
callback(e, null);
} else {
if(d.key) {
console.log(d.key);
}
console.log(d.vclock);
callback(null, d);
}
});
var value = {};
client.get({ 'bucket': 'my_bucket', 'key': 'my_key', 'type': 'my_bucket_type' }, function(e,d)
{
if (e) {
callback(e, {});
} else {
try
{
value = d.content[0].value;
value.vclock = d.vclock;
}
catch(ex)
{
value = {};
}
callback(null, value);
}
});
var options = {
q: {mykey1: "*value*"},
index: "my_search_index",
rows: 100,
start: 0
};
client.search(options, function(e, d)
{
if (e) {
callback(e, {count: 0, values: []});
} else {
var keys = null;
var num_found = 0;
try
{
num_found = d.num_found;
var keys = d.docs.map(function(doc){
var keyField = doc.fields.filter(function(d){
return (d['key'] == '_yz_rk') ? true : false;
});
var key = keyField[0]['value'];
return key;
});
}
catch(ex)
{
console.log("oops!");
}
callback(null, {count: num_found, values: keys});
}
});