I have a code like above. but I want it to work only if one of my variable has a value of 1. If the value of my variable is not 1, that is, if I did not specify a category from the link, I want it to include all categories.
It depends of which language you use. With JS you can do:
// With
pipeline = [] ;
category = "newbie" ;
my_variable = 1 ;
if ( my_variable == 1 ) pipeline.push( { "$match" : { category } } ) ;
// You end up with
[ { '$match': { category: 'web' } } ]
// And with
pipeline = [] ;
my_variable = 0 ;
if ( my_variable == 1 ) pipeline.push( { "$match" : { category } } ) ;
// You end up with
pipeline = [] ;
It is really simply if-then-else as offered by your programming language.
@Yung_Yudify, was my last post useful? If you were able to solve your issue with it please mark it as the solution as a courtesy to others. This way they will know they could follow the suggestion.