Skip to content

Instantly share code, notes, and snippets.

@neumino
Created April 5, 2013 18:49
Show Gist options
  • Select an option

  • Save neumino/5321667 to your computer and use it in GitHub Desktop.

Select an option

Save neumino/5321667 to your computer and use it in GitHub Desktop.
That works, but it's doesn't look good.
r.expr([
{
"sub_queries" : [
{
"sent_params" : {
"show_take_out_items" : null,
"show_in_store_items" : null,
"show_delivery_items" : null,
"location_id" : 448,
"category_id" : 5333
},
"rson_query" : "https://www.subtledata.com/API/M/1/?Q1=0205MkxGX0Fa|448|5333|||"
},
{
"sent_params" : {
"show_take_out_items" : null,
"show_in_store_items" : null,
"show_delivery_items" : null,
"location_id" : 448,
"category_id" : 5127
},
"rson_query" : "&Q2=0205|448|5127|||"
},
{
"sent_params" : {
"show_take_out_items" : null,
"show_in_store_items" : null,
"show_delivery_items" : null,
"location_id" : 448,
"category_id" : 5129
},
"rson_query" : "&Q3=0205|448|5129|||"
},
{
"sent_params" : {
"show_take_out_items" : null,
"show_in_store_items" : null,
"show_delivery_items" : null,
"location_id" : 448,
"category_id" : 5148
},
"rson_query" : "&Q14=0205|448|5148|||"
}
]
}
])
.map(function(doc) {
return doc.merge({ sub_queries: doc("sub_queries")
.limit(2)
.append(doc("sub_queries").nth(2).merge({response: "hello"}))
.union(doc("sub_queries").skip(3))
})
})
@neumino

neumino commented Apr 5, 2013

Copy link
Copy Markdown
Author
// Suppose the previous document is in the table temp.
// Since you probably have multiple documents and want to update just one, you have to add a .filter() after .table() and before .update()

r.db('test').table('temp').update(function(doc) {
  return doc.merge({ sub_queries: doc("sub_queries")
    .limit(2)
    .append(doc("sub_queries").nth(2).merge({response: "hello"}))
    .union(doc("sub_queries").skip(3))

  })
})

In python

r.db('test').table('temp').update(
    lambda doc: doc.merge({ 
        "sub_queries": doc["sub_queries"].limit(2)
            .append(doc["sub_queries"].nth(2).merge({"response": "hello"}))
            .union(doc["sub_queries"].skip(3))
    }) 
)

@sibblegp

sibblegp commented Apr 5, 2013

Copy link
Copy Markdown

Very helpful! Can you explain the limit/nth/skip pieces? Thanks!

@sibblegp

sibblegp commented Apr 5, 2013

Copy link
Copy Markdown

Oh wow.....this worked immediately. Thank you so much!

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