The following code works with no querystrings or one querystring only. In other words, simply going to /characters
returns all
You don't need to call Query#where
repeatedly, since you can pass all the conditions to Mongoose Model#find as:
var filteredQuery = {},
acceptableFields = ['gender', 'race', /* etc */ ];
acceptableFields.forEach(function(field) {
req.query[field] && filteredQuery[field] = req.query[field];
});
var query = Character.find(filteredQuery);
You'll also want to sanitize req.query
depending on the allowed parameters you have in mind.