Skip to content

Instantly share code, notes, and snippets.

@jakcharlton
Created December 23, 2013 01:45
Show Gist options
  • Save jakcharlton/8090696 to your computer and use it in GitHub Desktop.
Save jakcharlton/8090696 to your computer and use it in GitHub Desktop.
RethinkDB query/update
r.table("foo").get("idValue").update( function(doc) { return r.branch( doc.eq(A), B, {} ) })
@jakcharlton
Copy link
Author

cyounkins: Is it possible to do a compare-and-swap in Rethink? That is, replace the document with this id with B if it currently equals A.
[12:41pm] neumino: cyounkins, r.table("foo").get("idValue").update( function(doc) { return r.branch( doc.eq(A), B, {} ) })
[12:41pm] neumino: Not that A and B must have the same id since you cannot change the primary key of a document.
[12:42pm] cyounkins: neumino: Thanks! So .eq does a deep compare?
[12:43pm] neumino: cyounkins, yes

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