我正在建立一个MongoDB聚合管道,如果提供了一个参数,其中一部分正在使用$ match,否则尝试对所有内容进行$ match。
有一个方法self.products(),如果没有提供参数,它会返回我要查询的每个产品的列表,但我不知道如何将其集成或将$ match与通配符一起使用一切。
self.pipeline = [
{
'$lookup':
{
'from': 'timeseries',
'localField': '_id',
'foreignField': '_id',
'as': 'everything'
}
},
{
'$unwind': '$everything'
},
{
'$project': {
'_id': 1,
'header': 1,
'item': 1,
'data': '$everything.data'
}
},
{
'$match': {
'product.real': product if product else self.products()
}
}
]
答案 0 :(得分:0)
通过以下方式解决:
function sessionexists(){
if(!empty($_SESSION)){
return true;
}else{
return false;
}
}
if (!sessionexists()){
redirect("https://www.yoursite.com/");
exit();
}else{call_user_func('check_the_page');
}