rethinkdb / docs

RethinkDB documentation
http://rethinkdb.com/docs
Apache License 2.0
117 stars 167 forks source link

Add article on debugging techniques for reql #621

Open deontologician opened 9 years ago

deontologician commented 9 years ago

Recently, there was a question on the mailing list asking about debugging a secondary index (to make sure it had the expected values in it). @danielmewes responded with this generally helpful technique:

secondary index debugging

An easy way to check which keys will be inserted into a secondary index is by running a .map(secondaryIndexFunction.default(null)) on the table. If you want to create a multi index, you can replace the map by concatMap.

Assuming that you want to create a multi index so that you can look up messages by the IDs of their responses (in JS): r.table(...).indexCreate("resp_ids", function(x) { return x('response')('messages')('message-id'); }, {multi: true} )

other techniques

@neumino and @AtnNn both have a huge bag of reql tricks, some of which I bet are good for debugging

mlucy commented 9 years ago

Replacing val with val.do{|x| r.branch(test(x), x, r.error("..."))} to add asserts to your queries.