Skip to content

Instantly share code, notes, and snippets.

@thelinuxlich
Created July 31, 2014 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelinuxlich/677c710270cf41a55d78 to your computer and use it in GitHub Desktop.
Save thelinuxlich/677c710270cf41a55d78 to your computer and use it in GitHub Desktop.
query hell
// Getting all sessions by secondary index on client_id field, but excluding one client_id, so I return every client id from the clients table but the one not desired
r.db("aidax").table("sessions").getAll(
r.args(
r.db("aidax").table("clients")
.filter(
function(client) {
return client("id").ne("0f338aa9-0d16-4e00-8301-f5ddabf313de")
}
).map(function(client) {
return client("id")
}).coerceTo('array'))
,{index: "client_id"}
)
@AtnNn
Copy link

AtnNn commented Jul 31, 2014

r.db("aidax").table("clients")('id')
 .filter(r.row.ne("0f338aa9-0d16-4e00-8301-f5ddabf313de"))
 .map(function(client_id){
   r.db("aidax").table("sessions")
    .getAll(client_id, {index: 'client_id'})
    .concatMap(function(x){ return x; })
 })
r.db("aidax").table("sessions").filter(r.row('client_id').ne("0f338aa9-0d16-4e00-8301-f5ddabf313de"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment