This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table("foo").get("someid").filter( function(doc) { | |
doc("report")("statement")("name").eq("saymyname") | |
}).update({ | |
... | |
}).run( connection, callback ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').get(1).update( function(doc) { | |
return r.branch( | |
doc("value").default(0).lt(0), | |
{field: "newValue"}, | |
{} | |
) | |
}, {returnVals: true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').filter({username:"Michel"}) | |
.groupBy('origin', r.count) | |
.filter( r.row("reduction").gt(1)) | |
.map(function(result) { | |
return r.db('test').table('test') | |
.filter({username:"Michel", origin: result("group")("origin")}) | |
.coerceTo('array') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table("test").filter( function(doc) { | |
return doc("adresses").contains(function(adress) { | |
return adress("city").eq("Paris") | |
}) | |
}) | |
/* | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.table("t1").map( function(t1_doc) { | |
return t1_doc.merge({ | |
names: t1_doc("names").map( function(name) { | |
return r.table("t2").get(name)("name") | |
}) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('etdemo').table('et_metrics').groupedMapReduce( | |
// group -- we return the value that we are going to use to group | |
function(doc) { | |
// We group by logTime rouned to 5*60 (5 min) | |
return doc("logTime").sub( doc("logTime").mod(5*60) ) | |
}, | |
// map -- we return the value we are interested in | |
// count is to keep track of how many group we are | |
function(doc) { | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').filter(true)('id').limit(1).coerceTo('ARRAY').nth(0).do(function(idValue) { | |
return r.db('test').table('test').get(idValue).update({newField: "newValue"}, {returnVals: true}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').filter(true)('id').limit(1).coerceTo('ARRAY').nth(0).do(function(idValue) { | |
return r.db('test').table('test').get(idValue).update({newField: "newValue"}, {returnVals: true}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Data inserted | |
r.db('test').table('multi').insert({ | |
id:1, | |
field: [ | |
{key1: 1}, {key1: 2}, {key1: 3} | |
] | |
}) | |
r.db('test').table('multi').insert({ | |
id:2, | |
field: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r.db('test').table('test').map( function(doc) { | |
return r.expr(['id', 'value']).map( function(key) { | |
return r.expr([[key, r.expr([[doc(key).typeOf().default('UNDEFINED'), 1]]).coerceTo('OBJECT')]]).coerceTo('OBJECT') | |
}).reduce( function(left, right) { | |
return left.merge(right) | |
}) | |
}) |