I have multiple conditions for the query in my controller that I need path if exists.
condition 1 :
{ tags: mongoose.Types.ObjectId(req.params.tagId)}
condition 2:
{ reportedBy: { '$ne': req.user._id }} // if this video object reported dont show
condition 3:
{ owner: { '$ne': userblocks } } // userblocks is a array of objectIds
so this is my $match filter:
{
'$match':
_.isString(req.params.tagId) ?
{ tags: mongoose.Types.ObjectId(req.params.tagId),
reportedBy:{ '$ne': req.user._id}, owner: { '$ne': userblocks}}:
{ reportedBy:{ '$ne': req.user._id},owner: {'$ne': userblocks}}
},
I used ... spread operator if tagId passed to params.this condition works for tagId but other conditions are not working.
with @Anthony Winzlet hint I tried to :
{reportedBy:{ '$ne': mongoose.Types.ObjectId(req.user._id)},owner: {'$ne': userblocks}}
and userblocks is a list of objects, I checked the type of them and they are objects too.so no need to cast them to objectIds.