Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RethinkDB query/update
r.table("foo").get("idValue").update( function(doc) { return r.branch( doc.eq(A), B, {} ) })
@jakcharlton

This comment has been minimized.

Copy link
Owner Author

@jakcharlton jakcharlton commented Dec 23, 2013

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