Created
November 7, 2013 02:10
-
-
Save jamal/7347777 to your computer and use it in GitHub Desktop.
Hack to support an atomic filter and update with RethinkDB. This is useful for supporting something like a locking message queue. The problem here is that return_vals only works for single-row modifications, and filter() and limit() always returns multiple rows. At least, this was the simplest solution I could come up with.
This file contains 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
r.db("test").table("queue").filter({"available": true}).limit(1).forEach(function (row) { | |
return r.db("test").table("queue").get(row("id")).update({"available": false}, {return_vals: true}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@coffeemug: rethinkdb/rethinkdb#348