-
-
Save jakcharlton/8363967 to your computer and use it in GitHub Desktop.
This file contains hidden or 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}), | |
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