Mongoose optional search query parameters?
Build up your query object programmatically:
var query = {
player: 'player'
};
if (obj.action) {
query.action = obj.action;
}
Entry.find(query).exec(function(err, res){
console.log(res);
});
With ES6, you can do this with a splat & ternary like this:
Entry.find({
player: obj.player,
...obj.action ? { action: obj.action } : {}
})
.exec(function(err, res){
console.log(res);
});