I have the following situation. I need to build a mongoose request based on certain arguments, if any.
those. if an object like this is transferred
{ player: "nickname", action: "capture" }
the following search is performed:
Entry.find({ player: obj.player, action: obj.action }). exec(function(err, res){ console.log(res); });
If I need to exclude an βactionβ from the search, if the action is not in the object, what should I do? Using a ternary operator like action: (obj.action) ? obj.action:null action: (obj.action) ? obj.action:null does not work, nor does searching for records in the database, where action is null .
source share