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("users").filter( lambda user: | |
user["lst"].contains( lambda other_user: | |
other_user["name"] == "Bill" | |
) | |
) |
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
#!/bin/bash | |
if [ $# -eq 1 ] | |
NM=`uname -a && date` | |
NAME=`echo $NM | md5sum | cut -f1 -d" "` | |
then | |
ppa_name=`echo "$1" | cut -d":" -f2 -s` | |
if [ -z "$ppa_name" ] | |
then | |
echo "PPA name not found" | |
echo "Utility to add PPA repositories in your debian machine" |
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("authors").filter( function(author) { | |
return author("posts").contains( function(post) { | |
post("tags").contains("tagSearched") | |
}) | |
}).map( function(author) { | |
author.merge({ | |
posts: author("posts").filter( function(post) { | |
post("tags").contains("tagSearched") | |
}) | |
}) |
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('marvel').groupedMapReduce( | |
function(hero) { return hero('weightClass'), // group function | |
function(hero) { // map function | |
return { | |
strength: hero('strength'), | |
height: hero('height'), | |
count: 1 | |
} | |
}, | |
function(left, right) { // reduce function |
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( function(doc) { | |
return doc.keys().contains( function(key) { | |
return key.match("^(abc)") | |
}) | |
}) |
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("ScrobbleGraph").table("scrobbles").groupedMapReduce( | |
function(doc) { return doc("date").date() }, | |
function(doc) { return [doc] }, | |
function(left, right) { return left.add(right)} | |
) | |
// It's better to use just an orderBy and group on the client because | |
// - The database won't have to keep everything in memory | |
// - It's faster because of the index |
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('todomvc').table('posts').map( function(post) { | |
return post.merge({ | |
comments: r.db('todomvc').table('comments').filter( function(comment) { | |
comment("pid").eq( post("id") ) | |
}).coerceTo("ARRAY") | |
}) | |
}) | |
// If you have an index on pid for the table comments, you can do |
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("users").filter( function(user) { | |
// map over all the keys of search | |
return r.expr(search).keys().map( function(key) { | |
// for each key, we return a boolean weather user(key) match search(key) (case insensitive) | |
return user(key).match( r.expr("(?i)").add(r.expr(search)(key)) ).ne(null) | |
}).reduce( function(left, right) { // Then for each boolean, we return left and right // so we perform a "and" operation here. | |
return left.and(right) | |
}) | |
}) |
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
conn = r.connect() | |
cursor = r.db('gbrl').table('race').get_all(14136, index='season_id') \ | |
.pluck({'results':['driver', 'position']}, 'time') \ | |
.order_by('time') \ | |
.map( lambda race: | |
r.branch( # That's just a if | |
# Check if Andrew is in the results | |
race["results"]["driver"].contains("Andrew Vennaro"), | |
race["results"].filter(lambda doc: |
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('shred').table("teams").map(function(team) { | |
return team.merge({ | |
members: r.db('shred').table("users").filter(function(user) { | |
return team("members").contains(user("id")) | |
}).coerceTo("ARRAY") | |
}) | |
}) | |
// More efficient query that uses the index id |