RethinkDB is perfect for building dynamic queries based off any number of special conditions or input. The difficult part is trying to debug a dynamic query when something goes wrong. An easy way to see your final query is to convert the entire thing to a string and log it in the console before you run it.

Below is a typical example of how a query might be dynamically built in an application. Towards the bottom, you'll see that a simple .toString() appended to the end of the query when console logging will output the dynamically built query to the console.

var query = r.db('test_database').table('test_table')  
    .between(r.now().sub(86400), r.now(), {index: 'timestamp'});

if (some_condition) {  
    query = query.map(function(row) {
        return {
            // Some mapping stuff...
        };
    });
}

else {  
    query = query.map(function(row) {
        return {
            // Some other mapping stuff...
        }
    });
}

// Some other crazy dyanamic stuff...

// -------------------------------------------
// CONSOLE LOG YOUR QUERY BEFORE YOU RUN IT

console.log(query.toString());

// This will output something like:
// r.db('test_database').table('test_table')
//   .between(r.now().sub(86400), r.now(), {index: 'timestamp'})
//   .map(function(var_123) {return {...};}); 


// -------------------------------------------

query.run(conn, function(err, cursor) {  
    // Handle the result...
});

This will output your query it in its final state before you run it. You can copy and paste it from the the console into Sublime Text (or whatever editor you are using) and prettify it there. All the variables will be replaced, but it's much easier to debug now.