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('posts').indexStatus('oldIndex').nth(0).do(function(oldIndex) { | |
return r.table('posts').indexCreate('newIndex', oldIndex("function"), {multi: oldIndex("multi")}).do(function() { | |
return r.table('posts').indexWait('newIndex').do(function() { | |
return r.table('posts').indexRename('newIndex', 'oldIndex', {overwrite: 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.expr([{ v: 1 }, { v: 2 }, { v: 3 }, { v: 4 }]).map(function(doc) { | |
return [doc('v')] | |
}).reduce(function(left, right) { | |
return left.union(right).orderBy(function(element) { return element.mul(-1)}).limit(2) | |
}).nth(1) |
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
Possibly unhandled TypeError: Cannot call method 'call' of undefined | |
at tryCatch1 (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/util.js:43:21) | |
at CatchFilter$_doFilter [as doFilter] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/catch_filter.js:80:27) | |
at tryCatch1 (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/util.js:43:21) | |
at Promise$_callHandler [as _callHandler] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:627:13) | |
at Promise$_settlePromiseFromHandler [as _settlePromiseFromHandler] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:641:18) | |
at Promise$_settlePromiseAt [as _settlePromiseAt] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:800:14) | |
at Promise$_settlePromises [as _settlePromises] (/home/michel/projects/rethinkdb-all/thinky/node_modules/bluebird/js/main/promise.js:934:14) | |
at |
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
// Index: | |
r.table("heroes").indexCreate("idEquipment", function(doc) { | |
return doc("equipment").map(function(equipment) { | |
return [doc("id"), equipment] | |
}) | |
}, {multi: true}).run(conn, callback) | |
// Query | |
r.table("heroes").getAll([1, "boots"], {index: "idEquipment"}).run(conn, 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('marks') | |
.group('name') | |
.concatMap(function(row){return [row('course'), row('mark')];}) | |
.ungroup() | |
.map(function(res){ | |
return r.expr({name: res('group')}) | |
.merge(r.object(r.args(res('reduction')))); | |
}) |
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").groupedMapReduce( | |
function(doc) { return doc("categorie") }, | |
function(doc) { return doc.pluck("a", "b") }, | |
function(left, right) { | |
return { | |
a: left("a").add(right("a")), | |
b: left("b").add(right("b")) | |
} | |
} | |
).run(...) |
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('stuff').filter({'this_field' => 'this value'}).grouped_map_reduce( | |
lambda {|doc| doc[:this_other_field]} }, | |
lambda {|doc| [doc] }, | |
lambda {|left, right| left+right} | |
).run(conn) |
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").get("idValue").update(function(doc) { | |
return r.branch( | |
doc("lastUpdate").eq(newDoc["lastUpdate"]), | |
newDoc.merge({lastUpdate: r.now()}), | |
r.error("Wrong version") | |
) | |
}) |
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
// Retrieve all the documents where val == 1 | |
// If no document is returned, insert {newVal: 2} | |
// Else update all the documents with {newVal: 2} | |
// | |
// Note: This query is not atomic | |
r.table("test").filter({val: 1}).count().do(function(numResults) { | |
return r.branch( | |
numResults.eq(0), | |
r.table("test").insert({newVal: 2}), |
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
var rdbConn = {}; | |
var r = require('rethinkdb'); | |
if (r.protobuf_implementation !== 'cpp') console.log("WARNING: Wrong protobuf backend"); | |
var async = require('async'); | |
// Parameters | |
var numInserts = 5000; | |
// Global var |