Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// 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}),
r.table("test").filter({val: 1}).update({newVal: 2})
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment